1. 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.

form variables don't translate to Perl script

Discussion in 'Software Development' started by Auroralei, Sep 8, 2004.

Thread Status:
Not open for further replies.
  1. Auroralei

    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);
     
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 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/271772

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice