Line 34 reads '$rv = $sth->execute or die "Couldn't execute query: $dbh->errstr";'
Here is the contents of my perl script, it is supposed to print the cities of a state in a table that is 4 columns wide:
#!/usr/local/bin/perl use DBI; use CGI; use CGI::Carp qw(fatalsToBrowser); $buffer = $ENV{'QUERY_STRING'}; @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } ##Start database connections########################################## +########## $database = "database"; $db_server = "localhost"; $user = "user"; $password = "password"; ##Connect to database, insert statement, & disconnect ################ +########## $dbh = DBI->connect("DBI:mysql:$database:$db_server", $user, $password +); $statement = "SELECT city FROM database WHERE $FORM{state}"; $sth = $dbh->prepare($statement) or die "Couldn't prepare the query: $ +sth->errstr"; $rv = $sth->execute or die "Couldn't execute query: $dbh->errstr"; $rc = $sth->finish; $rc = $dbh->disconnect; ###################################################################### +########## print "Content-type: text/html\n\n"; #*******************************************Print to the first half of + page print <<EOF; <head> <title>xxx</title> <meta http-equiv="Content-Type" content="text/html; charset=xxx"> <link href="xxx.css" rel="stylesheet" type="text/css"> <style type="text/css"> <!-- .style1 {font-size: 36px} --> </style> </head> <body bgcolorxxx" leftmargin="0" topmargin="0" marginwidth="0" marginh +eight="0"> <table bgcolor="#FFFFFF" id="xxx" width="xxx" height="xxx" border="0" +cellpadding="0" cellspacing="0" align="center"> <tr> <td colspan="5"> <img src="xxx.gif" width="543" height="27">< +/td> <td colspan="2"> <a href="../"><img src="xxx.gif" width="xx" +height="xx" border="0"></a></td> <td colspan="2"> <a href="https://xxx.htm"><img src="xxx.gif" + width="x" height="x" border="0"></a></td> <td> <a href="xxx.htm" class="xxx" target="_blank +" onclick="window.open('../xxx.html','xxx','height=xxx,width=xxx,left=x +xx,top=xxx,toolbar=0,resizable=0,menubar=0'); return false"><img src= +"x.gif" width="102" height="27" border="0"></a></td> </tr> <tr> <td rowspan="3"> <img src="images/xxx.jpg" width="x" height="x" +></td> <td colspan="2" rowspan="3"> <img src="x.jpg" width="x" height="x"></td> <td colspan="3"> <img src="x" width="x" height="x"></td> <td colspan="4" rowspan="3"> <img src="x.jpg" width="x" height="x"></td> </tr> <tr> <td colspan="3"> <img src="x.gif" width="x" height="x"></td> </tr> <tr> <td colspan="3"> <img src="x.jpg" width="x" height="x"></td> </tr> <tr> <td> <img src="x.jpg" width="x" height="x"></td> <td> <a href="x.htm"><img src="x.gif" width="x" h +eight="x" border="0"></a></td> <td colspan="2"> <a hrefx"><img src="x.gif" width="x" height= +"x" border="0"></a></td> <td> <a><img src="x.gif" width="x" height="x" bor +der="0"></a></td> <td colspan="3"> <a href=x"><img src="x.gif" width="x" height +="x" border="0"></a></td> <td colspan="2"> <a href=x"><img src="x.gif" width="x" height +="x" border="0"></a></td> </tr> <tr> <td colspan="10"> <table id="x" width="x" height="x" border="0" +cellpadding="0" cellspacing="0"> <tr> <td height="1" colspan="3" nowrap valign="top"><di +v class="tabs"> <ul id="tablist"> <li id="overview" class=""> <a href="x">x</a> </li> <li id="x" class="selected"> <a href="x.html">x</a> </ul> <div style="clear:left;"></div> </div> <p align="center"> <script language="JavaScript" src="../x.js +"> </script> <FONT face="Arial Black" size=+1>$FORM{state} x</FONT></p> <P><DIV align=center></DIV> <TABLE cellSpacing=2 cellPadding=7 width="90%" align=center border=1> <TBODY> EOF #********************************************** Stop printing the firs +t half of the page $x=1; while (@row = $sth->fetchrow_array;) { print <<EOF; <TR> <TD width="25%"> <DIV align=center><FONT size=-1><B><FONT color=#2f2cff>$row[$x]</FONT><BR></B></FONT></DIV></TD> <TD width="25%"> <DIV align=center><FONT size=-1><B><FONT color=#x>$row[$x+2]</FONT><BR></B></FONT></DIV></TD> <TD width="25%"> <DIV align=center><FONT size=-1><B><FONT color=#x>$row[$x+3]</FONT><BR></A></B></FONT></DIV></TD> <TD width="25%"> <DIV align=center><FONT size=-1><B><FONT color=#x>$row[$x+4]</FONT><BR></B></FONT></DIV></TD> </TR> EOF $x=x+4; } print <<EOF; </TBODY> </TABLE> <BR> </td> </tr> </table></td> </tr> <tr> <td width="x" nowrap></td> <td width="x" nowrap></td> <td width="x" nowrap></td> <td width="x" nowrap></td> <td width="x" nowrap></td> <td width="x" nowrap></td> <td width="x" nowrap></td> </tr> </table><p> </p> </body> </html> EOF
In reply to Trying to print HTML table, erroring out.
by Anonymous Monk
in thread Print Array into 4 Column Table
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |