MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old July 7th, 2000, 02:01 PM
explore explore is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: TX
Posts: 38 explore User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Send a message via AIM to explore
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?

Reply With Quote
  #2  
Old July 9th, 2000, 02:05 AM
deviant deviant is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 27 deviant User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Can you be more specific??

Check your query, or check the error log...what message are you getting?

Reply With Quote
  #3  
Old July 10th, 2000, 09:55 AM
explore explore is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: TX
Posts: 38 explore User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Send a message via AIM to explore
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;
}

Reply With Quote
  #4  
Old July 10th, 2000, 11:19 AM
deviant deviant is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 27 deviant User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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;
}
}
}

Reply With Quote
  #5  
Old July 10th, 2000, 04:08 PM
explore explore is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: TX
Posts: 38 explore User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Send a message via AIM to explore
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;
}
}
}


Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Perl-->MySQL data read


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway