breal has asked for the wisdom of the Perl Monks concerning the following question:
key parts of listproducts.pl looks like:<form action="/cgi-bin/listproducts_test.pl" method = "GET"> <input type = "checkbox" name="list" value = 'book'>Book<br> <input type = "checkbox" ...will have extra checkboxes here<br> <input type = "submit" value = "list"> </form>
The die catch is telling my my SQL syntax is invalid, but I cant see why. This is a basic version of the syntax to highlight the SQL problem (points to the line indicated by #ERROR HERE). I plan to have additional values in the checkbox and use a foreach loop around the $dbh and $sth handles. Basically, ive got 3 tables of products and I want to be able to list all products in each table if checked in the checkbox. Am I on the right lines?#Create an instance of the CGI object $cgiobject = new CGI; #Output HTML header to the Web Browser print $cgiobject -> header; #Grab values submitted by the user my $product=$cgiobject ->param("list"); $dbh=DBI->connect("dbi:mysql:$userdb:$dbserveraddy","$username","$ +password") or die "Connection error: $DBI::errstr\n"; #Define MYSQL query - i think this is where I need assistance $sql = "Select * FROM ?"; $sth=$dbh->prepare($sql); $sth->execute($product) || + #ERROR HERE die "Could not execute SQL statement... maybe invalid syntax?"; print "<table border=2>"; #fetch each row and print results - also need assistance with this + if its wrong while (@results = $sth->fetchrow_array()) { foreach $result (@results){ if ($result eq $results) { print "<tr><td>$results</td></tr>"; } } } print "</table>"; $sth->finish; $dbh->disconnect;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: checkbox and mysql select
by moritz (Cardinal) on Apr 13, 2008 at 14:56 UTC | |
|
Re: checkbox and mysql select
by Anonymous Monk on Apr 13, 2008 at 14:49 UTC | |
by breal (Novice) on Apr 13, 2008 at 16:28 UTC | |
|
Re: checkbox and mysql select
by breal (Novice) on Apr 13, 2008 at 19:05 UTC | |
by Corion (Patriarch) on Apr 13, 2008 at 19:08 UTC |