|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
Can you be more specific??
Check your query, or check the error log...what message are you getting? |
|
#3
|
|||
|
|||
|
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; } |
|
#4
|
|||
|
|||
|
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; } } } |
|
#5
|
|||
|
|||
|
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; } } } |
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > Perl-->MySQL data read |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|