There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Software Development
Tag Cloud
adware audio blue screen boot bsod computer cpu crash dell desktop driver drivers error excel external hard drive firefox freezes freezing hard drive hardware hijackthis internet internet explorer itunes laptop malware mouse msn network networking outlook 2007 popups power printer problem ram router screen slow sound trojan usb virtumonde virus vista vista 32-bit windows windows xp winxp wireless
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
form variables don't translate to Perl script


Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
Auroralei's Avatar
Junior Member with 16 posts.
 
Join Date: Jun 2004
Experience: Perl greenie
08-Sep-2004, 07:20 PM #1
form variables don't translate to Perl script
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);
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:45 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.