in reply to Trying to print HTML table, erroring out.
in thread Print Array into 4 Column Table

Well, there are two things wrong with your prepare/execute. First of all, putting $dbh->errstr inside of a double-quoted string doesn't do what you want it to (it stringifies $dbh, and then it just keeps "->errstr" as part of the literal string). That should be:
... or die "Couldn't execute query: ".$dbh->errstr;
So that you can get some useful debugging information from the database.

Second (just to take a wild guess here), your query string looks something like "...&state=TX&..." which means that the way you need to generate your sql statement is more like:

$statement = "SELECT city FROM database WHERE state='$FORM{state}'";
Of course, this would be very BAD because you're not stripping single-quotes from your state, and besides, queries should use bound placeholders (in general). So what it should actually be is:
$statement = "SELECT city FROM database WHERE state=?"; $sth = $dbh->prepare($statement) or die "Couldn't prepare the query: " +.$sth->errstr; $rv = $sth->execute($FORM{state}) or die "Couldn't execute query: ".$d +bh->errstr;
If that's over your head, the short answer is that that question-mark in the query works kind of like a %d would in printf. Anyway, you should read the DBI docs about placeholders (also called "bind variables" or "binds") for more info.

Oops... see UPDATE comment below.

Last, you're actually going to want to fetch the data from that query and do something with it. That will probably look something like (and there are many ways to do this... but here's one way):

# inside the html <table> foreach my $row ($sth->fetchall_arrayref) { my $state = $row->[0]; print "... some html or other based on $state..."; }

Anyway, it appears that you're gonna want to do some documentation reading and possibly looking at more example code.

Oh... and I didn't bother to look any further down than the query, because that is clearly going wrong right now... you need to resolve this problem before you worry about how you the html in exactly whatever way you want. Learn to walk before you learn to run, and all.

Good luck.

P.S. Oh, and I'll leave the rant about how you should be using CGI.pm to someone else :-)

UPDATE: Actually, I made a mistake by not looking closely enough all the way to the bottom... you are fetching the results (which is good). BUT since you are calling $sth->finish and $dbh->disconnect at the top of the script and doing your fetching at the bottom of the script (after finishing and disconnecting), that's gonna break. (Also, this is why I missed the fetching down below... I assumed (like the code would) that once you have disconnect from the DB, you're not doing any further calls against the DB.) What this is means is: move the finish and disconnect to the bottom after you have fetched.

------------ :Wq Not an editor command: Wq