#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    TX
    Posts
    38
    Rep Power
    15
    I am having problems getting the data submitted via an html form--> parsed to a perl script --> to mysql database. I know that the connection is correct because I can log into the database and insert data and I created an html page to read in the contents of the database. But I can not get the contents that a "user" submits via the form to "feed/load" in the mysql database.

    Anyone have any ideas?
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    27
    Rep Power
    0
    Can you be more specific??

    Check your query, or check the error log...what message are you getting?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    TX
    Posts
    38
    Rep Power
    15
    The error saids, "Data was NOT entered due to errors".

    Here is the code that produced the error:


    #!/usr/bin/perl

    require "dbi-lib.pl";


    #----------------------#
    # User Variables #
    #----------------------#

    $table_name = "addressbook";

    #----------------------#
    # Main Body #
    #----------------------#

    &parse_input;
    &print_header;


    if (&check_input) {
    &initialize_dbi;
    $birthday = &birthday;
    &run_statement("insert into $table_name(first_name,last_name,phone, address,city,state,birthday)
    VALUES('$form_data{'first_name'}', '$form_data{'last_name'}',
    '$form_data{'phone'}', '$form_data{'address'}',
    '$form_data{'city'}', '$form_data{'state'}',
    $form_data{'zipcode'}, '$birthday')");
    print "Data was successfully enteredn";
    }
    else { print "Data was NOT entered due to errors.n"; }
    exit;
    #----------------------#
    # Functions #
    #----------------------#

    sub check_input {
    if ($form_data{'first_name'} && $form_data{'last_name'} &&
    $form_data{'phone'} && $form_data{'address'} &&
    $form_data{'city'} && $form_data{'state'} &&
    $form_data{'zipcode'} && $form_data{'month'} &&
    $form_data{'day'} && $form_data{'year'}) {
    return 1;
    }
    return 0;
    }
    sub birthday {
    local $birthday = $form_data{'year'}."-".$form_data{'month'}."-".$form_data{'day'};
    return $birthday;
    }
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    27
    Rep Power
    0
    this may help....

    Simpilize your parse and variable methods by using the following code as your parse sub routine......then you can use the variables from your html form as normal variables....ie <input name=variable> parses into your perl script as $variable instead of $form_data{'variable'}......just be sure to parse early in the script..

    -deviant-

    sub parse_form
    {
    my( @pairs, $value, $name, $buffer );
    if ( $ENV{'REQUEST_METHOD'} eq 'GET' )
    {
    @pairs = split( /&/, $ENV{'QUERY_STRING'} );
    }
    elsif ( $ENV{'REQUEST_METHOD'} eq 'POST' )
    {
    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'} );
    @pairs = split( /&/, $buffer)
    }
    else { die("unknown REQUEST_METHOD!n") }

    foreach $pair (@pairs)
    {
    ($name, $value) = split( /=/, $pair);
    $name =~ tr/+/ /;
    $value=~ tr/+/ /;
    $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $name =~ s/<!--(.|n)*-->//g;
    $value =~ s/<!--(.|n)*-->//g;
    $value =~ s/(n)//g;
    $value =~ s/'/'/g; #escape ' for mysql
    if( ($name =~ /([])/g) )
    {
    $name =~ s/[]//g;
    push @$name, $value;
    }
    else
    {
    $$name = $value;
    }
    }
    }
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    TX
    Posts
    38
    Rep Power
    15
    I tried that and instead of getting an error message, I got a blank page after hitting submit. I checked the database and the entry was not there. Here is what the code looks like now:

    #!/usr/bin/perl

    require "dbi-lib.pl";

    #----------------------#
    # User Variables #
    #----------------------#

    $table_name = "addressbook";

    #----------------------#
    # Main Body #
    #----------------------#

    &parse_input;
    &print_header;


    if (&check_input) {
    &initialize_dbi;

    &run_statement("insert into $table_name(first_name,last_name,phone,address,city,state,zipcode)
    values($first_name,$last_name,$phone,$address,$city,$state,$zipcode)");
    print "Data was successfully enteredn";
    }
    else { print "Data was NOT entered due to errors.n"; }
    exit;

    #----------------------#
    # Functions #
    #----------------------#


    sub parse_form
    {
    my( @pairs, $value, $name, $buffer );
    if ( $ENV{'REQUEST_METHOD'} eq 'GET' )
    {
    @pairs = split( /&/, $ENV{'QUERY_STRING'} );
    }
    elsif ( $ENV{'REQUEST_METHOD'} eq 'POST' )
    {
    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'} );
    @pairs = split( /&/, $buffer)
    }
    else { die("unknown REQUEST_METHOD!n") }

    foreach $pair (@pairs)
    {
    ($name, $value) = split( /=/, $pair);
    $name =~ tr/+/ /;
    $value=~ tr/+/ /;
    $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $name =~ s/<!--(.|n)*-->//g;
    $value =~ s/<!--(.|n)*-->//g;
    $value =~ s/(n)//g;
    $value =~ s/'/'/g; #escape ' for mysql
    if( ($name =~ /([])/g) )
    {
    $name =~ s/[]//g;
    push @$name, $value;
    }
    else
    {
    $$name = $value;
    }
    }
    }

Similar Threads

  1. DEBUGGER in VC++ dumping memory leaks
    By kavi_s in forum C Programming
    Replies: 3
    Last Post: December 3rd, 2004, 02:00 PM
  2. storing binary data in perl
    By sun in forum Perl Programming
    Replies: 0
    Last Post: November 12th, 2003, 09:46 AM
  3. Replies: 4
    Last Post: September 18th, 2003, 12:14 AM
  4. read POST data in javascript?
    By rorwell in forum JavaScript Development
    Replies: 7
    Last Post: July 16th, 2003, 11:51 AM
  5. Hello Perl Land
    By if(Kevin) in forum Perl Programming
    Replies: 4
    Last Post: July 26th, 2001, 12:28 PM

IMN logo majestic logo threadwatch logo seochat tools logo