jtm62 has asked for the wisdom of the Perl Monks concerning the following question:
I am working on a project for class and I am having some trouble getting my data inserted into the database properly. First, data is input into a form, and upon submit a new script to insert that data entered into the tables is executed. I fairly certain I know where the problem is (bold in code) but I don't know how to fix it.
The code queries different tables in the database to present drop down boxes of valid selections. That works properly, I have tested it.
<form name="ClassInfo" method="post" action="inputclass.cgi"> <h3 class="style1">Class Information</h3> [B]<p class="style1">Instructor: <select name="teacher" style="w +idth: 150px"> <option></option> EOF $statement1 = "Select emp_ID, fname, lname From employees Wher +e is_prof=1"; $sth1 = $dbh->prepare($statement1); $sth1->execute; my %row; $sth1->bind_columns( \( @row{ @{$sth1->{NAME_lc} } } )); while($sth1->fetch){ print"<option value=\"$row{emp_id}\">$row{fname} $r +ow{lname}</option>"; } print <<EOF; </select></p> <p class="style1">Sales Person: <select name="salesperson" style +="width: 150px"> <option></option> EOF $statement2 = "Select emp_ID as emp_id2, fname as fname2, lnam +e as lname2 From employees Where is_salerep=1"; $sth2 = $dbh->prepare($statement2); $sth2->execute; my %row; $sth2->bind_columns( \( @row{ @{$sth2->{NAME_lc} } } )); while($sth2->fetch){ print"<option value=\"$row{emp_id2}\">$row{fname2} +$row{lname2}</option>"; } print <<EOF; </select></p> <p class="style1">Course: <select name="course" style="width: 15 +0px"> <option></option> EOF $statement3 = "Select course_ID, cname From courses"; $sth3 = $dbh->prepare($statement3); $sth3->execute; my %row; $sth3->bind_columns( \( @row{ @{$sth3->{NAME_lc} } } )); while($sth3->fetch){ print"<option value=\"$row{course_id}\">$row{cname}</optio +n>"; } print <<EOF; </select></p> <p class="style1">Buyer: <select name="comid" style="width: 150p +x"> <option></option> EOF $statement4 = "Select com_ID, cname as comname From companies" +; $sth4 = $dbh->prepare($statement4); $sth4->execute; my %row; $sth4->bind_columns( \( @row{ @{$sth4->{NAME_lc} } } )); while($sth4->fetch){ print"<option value=\"$row{com_id}\">$row{comname}</option +>"; }[/B] print <<EOF; </select></p> <p class="style1">Date Sold (YYYY/MM/DD): <input name="ds" type="text" style="width: 101px" size="5" /> </p> <p class="style1">Price Sold For: <input name="ps" type="text" style="width: 101px" size="5" /> </p>
Here I insert the data received above as a new entry into the three tables shown below. The addresses table entry is built properly. The problem lies somewhere within the classes table because the entry does not populate. I feel undefined data is being sent by one of the columns.
$dbh->do("Insert into addresses values ($aid, '$formValues{'street1'}', '$formValues{'street2'}', '$fo +rmValues{'city'}', '$formValues{'state'}', $formValues{'zip'})"); print"<p>finished addresses</p>"; $dbh->do("Insert into classes values ($clid, $formValues{'teacher'}, $formValues{'course'}, $aid, $f +ormValues{'sd'}, $formValues{'st'}, $formValues{'ed'}, $formValues{'et'})"); print"<p>finished classes</p>"; $dbh->do("Insert into sell values ($tid, $formValues{'salesperson'}, $clid, $formValues{'comid'}, + $formValues{'ps'}, '$formValues{'ds'}')");
formValues comes from a .pm file code to parse is:
sub parseForm { local($in, %in) ; local($name, $value) ; # First, read entire string of CGI vars into $in if ( ($ENV{'REQUEST_METHOD'} eq 'GET') || ($ENV{'REQUEST_METHOD'} eq 'HEAD') ) { $in= $ENV{'QUERY_STRING'} ; } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { if ($ENV{'CONTENT_TYPE'}=~ m#^application/x-www-form-urlencode +d$#i) { $ENV{'CONTENT_LENGTH'} || &HTMLdie("No Content-Length sent with the POST requ +est.") ; read(STDIN, $in, $ENV{'CONTENT_LENGTH'}) ; } else { &HTMLdie("Unsupported Content-Type: $ENV{'CONTENT_TYPE'}") + ; } } else { &HTMLdie("Script was called with unsupported REQUEST_METHOD.") + ; }
with command (perl -w #filename) the error message returned is: Script was called with unsupported REQUEST_METHOD. I built the form with post... and post is a valid request method. I am also told: (Use of uninitialized value in string eq at functions.pm line 23.) line 23 is ( if ( ($ENV{'REQUEST_METHOD'} eq 'GET') ||)
for more information is needed, I will be glad to provide it! Thanks all!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: unsupported REQUEST_METHOD?
by zwon (Abbot) on Nov 14, 2009 at 21:47 UTC | |
by Anonymous Monk on Nov 15, 2009 at 00:18 UTC | |
|
Re: unsupported REQUEST_METHOD?
by zentara (Cardinal) on Nov 15, 2009 at 14:21 UTC | |
|
Re: unsupported REQUEST_METHOD?
by Anonymous Monk on Nov 15, 2009 at 15:16 UTC | |
by jtm62 (Initiate) on Nov 15, 2009 at 17:43 UTC | |
by Anonymous Monk on Nov 15, 2009 at 18:24 UTC | |
by jtm62 (Initiate) on Nov 15, 2009 at 18:30 UTC | |
by Anonymous Monk on Nov 15, 2009 at 18:54 UTC | |
| |
|
Re: unsupported REQUEST_METHOD?
by jtm62 (Initiate) on Nov 15, 2009 at 17:50 UTC |