Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with scritp

Status
Not open for further replies.

Newbie123456

Technical User
May 15, 2006
2
CA
i have a problem with my script. its not parsing the form:

Code:
#!/usr/bin/perl -w

print "Content-type: text/html\n\n";

use CGI qw/:standard/;

# SUBROUTINES!

$action = param('action');

if ($action eq "") {
&intro;
}
if ($action eq "send") {
&send;
}

# PARSE FORM!

if ($ENV{'REQUEST_METHOD'} eq 'POST') {
  read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
} else {
  $buffer = $ENV{'QUERY_STRING'};
}
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
  ($name, $value) = split(/=/, $pair);
  $name =~ tr/+/ /;
  $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  $value =~ tr/+/ /;
  $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  $in{'$name'} = $value;
}

sub intro {

print<<THIS;

[b]NOT SHOWN[/b]

THIS

}

sub send {

[b]NOT SHOWN[/b]

}

sub MessageError {

$ErrorMessage = shift;

print<<THIS;

[b]NOT SHOWN[/b]

THIS

exit;

}

1;

please tell me whats wrong and how to fix it. thanks.
 
If you're gonna use CGI.pm, then you don't need the second form parse. Here's your new code:

#!/usr/bin/perl -w

use CGI; #loads cgi.pm.
use CGI qw:)all);

print header;

# SUBROUTINES!

$action = param('action');

if ($action eq &quot;&quot;) {
&intro;
}
if ($action eq &quot;send&quot;) {
&send;
}


sub intro {

print<<THIS;

NOT SHOWN

THIS

}

sub send {
$input = param('form_field_name');
print &quot;Here's the input: $input<br>&quot;;
}

sub MessageError {

$ErrorMessage = shift;

print<<THIS;

NOT SHOWN

THIS

exit;

}

Hope this helps. There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
i did it and i get the same errors here i'll show more of my code:

Code:
#!/usr/bin/perl -w

use CGI; #loads cgi.pm.
use CGI qw(:all); 

print header;

######################################################################
# EDIT THESE VARIABLES BELOW!
######################################################################

$IP = $ENV{'REMOTE_ADDR'}; # The person's IP address when they use the script.
$UsePassword = &quot;1&quot;; # 1 = yes, 0 = no
$Password = &quot;admin&quot;; # Your administrator password
$Sendmail = &quot;/usr/sbin/sendmail&quot;; # Your web servers sendmail location

######################################################################
# DON'T EDIT ANYTHING BELOW UNLESS YOU KNOW WHAT YOU'RE DOING
######################################################################

# SUBROUTINES!

$action = param('action');

if ($action eq &quot;&quot;) {
&intro;
}
if ($action eq &quot;send&quot;) {
&send;
}

sub intro {

print<<THIS;

[b]NOT SHOWN[/b]

THIS

}

sub send {

$input1 = param('To');
$input8 = param('Password');

# VALIDATE FORMS!

if ($input1 =~ /[a-zA-Z0-9]/) {
&MessageError(&quot;&quot;);
}

[b]NOT SHOWN[/b]

# CHECK IF PASSWORD IS USED/ENTERED CORRECTLY, ET CETERA!

if ($UsePassword eq &quot;1&quot;) {
if ($input8 ne &quot;$Password&quot;) {
&MessageError(&quot;Invalid password!&quot;);
}
}

[b]NOT SHOWN[/b]

}

sub MessageError {

$ErrorMessage = shift;

print<<THIS;

[b]NOT SHOWN[/b]

THIS

exit;

}

1;

its still not parsing forms
 
Maybe it's the HTML. Maybe your HTML <form action=&quot;script.cgi&quot; method=&quot;POST&quot;> is not on the top. Also, take off that '1' from the bottom. The reason the code didn't parsed last time is because you didn't print anything. Here's how I write the same script:


#!/usr/bin/perl -w

use CGI; #loads cgi.pm.
use CGI qw:)all);

print header;

#edit

$IP = $ENV{'REMOTE_ADDR'}; # The person's IP.
$UsePassword = &quot;1&quot;; # 1 = yes, 0 = no
$Password = &quot;admin&quot;; # Your administrator password
$Sendmail = &quot;/usr/sbin/sendmail&quot;; # Your web servers sendmail location

#You've finished defining the variables. If you want to,
# you can continue screwing with the script, but it isn't #necessary.

# SUBROUTINES!

$action = param('action');

if ($action eq &quot;&quot;) {
&intro;
}
if ($action eq &quot;send&quot;) {
&send;
}

sub intro {

print<<THIS;

NOT SHOWN

THIS

}

sub send {

$input1 = param('To');
$input8 = param('Password');

# VALIDATE FORMS!

if ($input8 =~ /[a-zA-Z0-9]/) {
print &quot;Input: $input8<br>&quot;; #don't call the error message if it doesn't need. But you can also use that for the header.
}


# CHECK IF PASSWORD IS USED/ENTERED CORRECTLY, ET CETERA!

if ($UsePassword eq &quot;1&quot;) {
if ($input8 ne &quot;$Password&quot;) {
&MessageError(&quot;Invalid password!&quot;);
}else{
print &quot;Password is correct.&quot;;
}

}
} #this one is the closing of 'send' subroutine.

sub MessageError {

$ErrorMessage = @_;

print<<THIS;

NOT SHOWN

THIS

exit;

}

There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
heres what the form tags are:

<FORM NAME=&quot;script&quot; ACTION=&quot;script.cgi&quot; METHOD=&quot;POST&quot;>
<INPUT TYPE=&quot;HIDDEN&quot; NAME=&quot;action&quot; VALUE=&quot;send&quot;>
 
Put the tag <FORM NAME=&quot;script&quot; ACTION=&quot;script.cgi&quot; METHOD=&quot;POST&quot;> top of all the HTML fields and try. An example:

Code:
<form action=&quot;boards.cgi&quot; method=&quot;GET&quot;>

    <input type=&quot;hidden&quot; name=&quot;bid&quot; value=&quot;$pbid&quot;><input
    type=&quot;hidden&quot; name=&quot;mode&quot; value=&quot;post_msg&quot;><input
    type=&quot;hidden&quot; name=&quot;pass&quot; value=&quot;$epass&quot;><input
    type=&quot;hidden&quot; name=&quot;user&quot; value=&quot;$userid&quot;><blockquote>
        <blockquote>
            <blockquote>
                <blockquote>
                    <blockquote>
                        <p align=&quot;left&quot;> </p>
                    </blockquote>
                </blockquote>
            </blockquote>
        </blockquote>
    </blockquote>
    <p align=&quot;left&quot;><font size=&quot;2&quot; face=&quot;Arial&quot;><u>Start a New
    Topic</u></font></p>
    <p align=&quot;left&quot;><font size=&quot;2&quot; face=&quot;Arial&quot;>Subject <br>
    </font><input type=&quot;text&quot; size=&quot;31&quot; name=&quot;subject&quot;
    value=&quot;&quot;></p>
    <p align=&quot;left&quot;><font size=&quot;2&quot; face=&quot;Arial&quot;>Body<br>
    </font><textarea name=&quot;body&quot; rows=&quot;6&quot; cols=&quot;31&quot;></textarea></p>
    <blockquote>
        <blockquote>
            <blockquote>
                <p align=&quot;left&quot;><input type=&quot;submit&quot; value=&quot;Post&quot;></p>
            </blockquote>
        </blockquote>
    </blockquote>
</form>
There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
thats how i did it:

Code:
<FORM NAME=&quot;script&quot; ACTION=&quot;script.cgi&quot; METHOD=&quot;POST&quot;>
<INPUT TYPE=&quot;HIDDEN&quot; NAME=&quot;action&quot; VALUE=&quot;send&quot;>

[i]TABLE WITH FORM FIELDS[/i]

</form>

and it still does the same thing
 
The code seems fine to me. No idea what's causing the error. There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
well, i was wondering if i could email you the script so you could see the entire code or, do you want to talk on yahoo messenger or somthing ?
 
You may email the code to projectnet01@yahoo.com There is no Knowledge that is not power.
Age: 16
E-mail: projectnet01@yahoo.com
School: Coral Springs High (Company:(not done yet) :)
Status: Currently working with C++ for game developing. And making a musical band.
-Aaron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top