PDA

View Full Version : Stuck with CGI


billy878
02-06-02, 04:42 PM
Does anyone know why this doesn't work? I am very stuck

"products" is just a plain text file created in emacs

its content is

vac354; vacuum cleaner; 5; 45.80

this is the CGI scipt. The search page runs correctly as far as I can tell. but it never creates the result

#!/usr/bin/perl
$datafile = "products";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@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;
$FORM{$name} = $value;
}

$searchstr = $FORM{'name'};

open(INF,$datafile);
@mydata = <INF>;
close(INF);
print "Content-type:text/html\n\n";
print "<html><head><title>Search Results</title></head>\n";
print "<body><h3>Search Results</h3>\n";

@results = grep(/$searchstr/i,@mydata);
if ($#results >= 0) {
foreach $i (@results) {
chomp($i);
($stocknum,$name,$status,$price) = split(/\;/,$i);
print "<b>$name</b> (#$stocknum) - \$$price<br>\n";
}
} else {
print "No results found.<p>\n";
}
print "</body></html>\n";

Am I dumb what have I missed

Thanks
:confused: