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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI and Data Transfer

Status
Not open for further replies.

samesale

Programmer
Sep 15, 2003
133
0
0
US
I rewrote a program to pass on values from an HTML program to a CGI program. However, the CGI is not printing it. I suspect that the program is not receiving the data. I have used the same code in other programs and it works. Please help. The CGI program is:

#!/usr/bin/perl

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

use CGI;

$query = new CGI;

print "test";

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

@pairs = split(/&/, $buffer);

%FORM = ();

foreach $pair (@pairs) {
$pair =~ s/\+/ /g;

($name, $value) = split(/=/, $pair);

$value =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("c", hex($1))/eg;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("c", hex($1))/eg;
$value =~ s/\n/ /g; # replace newlines with spaces
$value =~ s/\r//g; # remove hard returns
$value =~ s/\cM//g; # delete ^M's

$FORM{$name} = $value;
}
foreach $key('make','model','mile','year','price')
{
print " $FORM{'make'}<br>";
print " $FORM{'model'}<br>";
print " $FORM{'mile'}<br>";
}

print "test1";
 
Try this:

Code:
#!/usr/bin/perl

use CGI qw(param);
use CGI::Carp qw(fatalsToBrowser);

my $make = param("make");
my $model = param("model");
my $mile = param("mile");
my $year = param("year");
my $price = param("price");

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

print <<EOF;
<html>
<head></head>
<body>
$make<br>
$model<br>
$mile<br>
$year<br>
$price
</body>
</html>

EOF

This will let you know right away if the data is getting passed to the script. Also, make sure the you have at least one carriage return after EOF. Otherwise you'll get an error. Additionally, note the use of "Fatals to browser". If you don't have easy access to your error logs, this is a good way to see what's happening in your script as a lot of common errors are echoed to the browser.

There's always a better way. The fun is trying to find it!
 
Thank you very much, it does print the result. I do not know why my program does not work. But, anyway, I appreciate your help. Thanks again.
 
Glad to help...

There's always a better way. The fun is trying to find it!
 
could it be lack of a space?

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


Kind Regards
Duncan
 
I got the solution. It works. Thanks to all who helped. I appreciate everyone's time and help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top