PDA

View Full Version : A beginner problem, getting started


Kosko
11-09-2004, 06:10 AM
I've installed and run perl, cgi, and an
localhost web server onto my homecomputer. I've run simple
scripts on each kind to make sure they work, and they were
going fine. I tried incorporating a form with cgi and got a
problem though. The form calls the cgi script correctly and
the cgi will display the correct text back in the browser. A
problem comes when I try to set the perl variable equal to
the value passed in by the form. When I comment that line
out, the script will work, when I put the line in, the script
stops working. I've checked the names between the two pieces
of code about a million times. I was wondering if you could
see anything that I'm missing. Any help would be great,
thanks.


This is the HTML(saved as testcgi.html):

<FORM ACTION="http://localhost/cgi-bin/perltest.cgi"
METHOD=POST>

Test Data: <INPUT TYPE="checkbox" NAME="value" VALUE="BAH">
Test Data: <INPUT TYPE="text" NAME="data" VALUE="BAH">

<INPUT TYPE="submit" VALUE="Input">
<INPUT TYPE="reset" VALUE="Reset">

This is the perl(saved as perltest.cgi):

#!/usr/local/bin/perl -wT
use strict;
use CGI ':standard:';

my $test; #i can leave this line in and it still works

#$test=param('value'); #this is the problem line

#i've also tried making it a double =,didn't make a difference

print "Content-type: text/html\n\n";
print "The server works $test";
</FORM>

Kosko
11-09-2004, 06:16 AM
i've even done a syntax check on the cgi and it was ok.

mlseim
11-09-2004, 01:50 PM
Have you tried anything like this?
=========================================================

#!/usr/local/bin/perl -wT
use strict;
use CGI ':standard:';

### PARSE INCOMING FORM VARIABLES ###

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
if (length($buffer) < 5) {
$buffer = $ENV{QUERY_STRING};
}

@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/'//g;
$value =~ s/&/and/g;
$value =~ s/\"//g;
$value =~ s/\+//g;
$param{$name} = $value;
}

$test = $param{'value'};

print "Content-type: text/html\n\n";
print "The server works $test";

=========================================================

.... I also noticed you have 'param{'value'} without the '$' (you need that).

--max--

YUPAPA
11-12-2004, 09:21 AM
I've installed and run perl, cgi, and an
localhost web server onto my homecomputer. I've run simple
scripts on each kind to make sure they work, and they were
going fine. I tried incorporating a form with cgi and got a
problem though. The form calls the cgi script correctly and
the cgi will display the correct text back in the browser. A
problem comes when I try to set the perl variable equal to
the value passed in by the form. When I comment that line
out, the script will work, when I put the line in, the script
stops working. I've checked the names between the two pieces
of code about a million times. I was wondering if you could
see anything that I'm missing. Any help would be great,
thanks.


This is the HTML(saved as testcgi.html):

<FORM ACTION="http://localhost/cgi-bin/perltest.cgi"
METHOD=POST>

Test Data: <INPUT TYPE="checkbox" NAME="value" VALUE="BAH">
Test Data: <INPUT TYPE="text" NAME="data" VALUE="BAH">

<INPUT TYPE="submit" VALUE="Input">
<INPUT TYPE="reset" VALUE="Reset">

This is the perl(saved as perltest.cgi):

#!/usr/local/bin/perl -wT
use strict;
use CGI ':standard:';

my $test; #i can leave this line in and it still works

#$test=param('value'); #this is the problem line

#i've also tried making it a double =,didn't make a difference

print "Content-type: text/html\n\n";
print "The server works $test";
</FORM>

Try calling it directly instead of storing it in a variable and then call it.
If you don't check the checkbox named value, $cgi->param('value') may not contain any values. If you check the checkbox, then $cgi->param('value') should return 'BAH'


#!/usr/bin/perl
use strict;
use CGI qw(:standard);

my $cgi = new CGI;

print $cgi->header(-type=>'text/html');
print $cgi->param('value');

__END__



.... I also noticed you have 'param{'value'} without the '$' (you need that).

--max--

He is trying to get the value from a method. It is not a hash.

schleppel
11-14-2004, 02:07 PM
don't you just need to put


my $test = param('value');