form variables don't translate to Perl script

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Auroralei

Thread Starter
Joined
Jun 10, 2004
Messages
16
Hi, I'm hoping that someone can take a look at my script.

I'm using Perl in combination with mySQL, with variables read in from an html form. The problem seems to be that the variables don't get read in properly.

It connects to SQL fine, but then gives the message "there is no matching image for item" (it doesn't print the $item_number variable -- none seems to be present, although I have posted from a form with "hidden" input type names and values).

When I subsitute the literal filename for the variable, it works perfectly.

Here's the script:

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

my $query;
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 {


my $image_dir = "http://www.mysite.com/dir";
my $path_sep = "/";


my $dbh = &connect;


my $finished = $dbh->selectrow_array ("SELECT printfinished FROM images WHERE webfinished = '$item_number'") or die "No matching image for item $item_number";
my $line = $dbh->selectrow_array ("SELECT printline FROM images WHERE webfinished = '$item_number'") or die "No matching image for item $item_number";


my $finished_path = $image_dir . $path_sep . $finished . ".jpg";
my $line_path = $image_dir . $path_sep . $line . ".jpg";


$dbh->disconnect ();

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

<img src=$finished_path width="300" height="300" border=1></td>
<img src=$line_path width="300" height="300" border=1></td>

}
}

sub connect
{
my $db = "xxxxxxx";
my $host = "xxxxxxxxx";
my $db_user = "xxxxxxxx";
my $db_password = "xxxxxxx";
my $dsn = "dbi:mysql:$db:$host";

return (DBI->connect ($dsn, $db_user, $db_password, {PrintError => 0, RaiseError =>1}));
}



exit (0);
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top