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

Where are my variables??

Status
Not open for further replies.

ramouski

Programmer
Sep 13, 2004
1
US
I'm sure I'll feel silly when I find out the answer to this!

I have a very simple script and a very simple form.

My problem is that when i send the form variables to the script, I can't do anything with them. See the script below: All I want it to do is print "The item number is "item_number". What I get is "The item number is (blank)"

Can someone please tell me what the problem is?

#!/usr/bin/perl
use strict;
use lib qw(C:/Perl/lib);
use CGI qw:)standard escapeHTML);
use DBI;

my $query;
my %form;
my $item_name;
my $item_number;

my @pairs;
my $pair;
my $name;
my $value;


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

%form = &parse;


$item_name = $form{item_name};
$item_number = $form{item_number};


&deliver_product;


sub parse {
@pairs = split(/&/, $query);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$form{$name} = $value;
}


sub deliver_product {


print <<EOF;
Content-Type: text/html\n\n

<html>
<head>
<title></title>
</head>
<body>
The item number is $item_number
</body>

</html>
EOF
}
}

exit (0);




And here's the form I use:

<HTML>
<head>
</head>

<body>

<form method="post" action=" target="_blank">
<input type="hidden" name="item_name" value="Fairy Girl on Ladybug Flower">
<input type="hidden" name="item_number" value="BPFAGI0002FWP">
<input type="submit" value="Test IPN">
</form>

</BODY>
</HTML>
 
Try moving the BOLD lines below your parse subroutine like this:

Code:
sub parse {
@pairs = split(/&/, $query);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$form{$name} = $value;
}

[B]
$item_name = $form{item_name};
$item_number = $form{item_number};
[/B]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top