Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

post data from db on website

by baperl (Sexton)
on Oct 10, 2011 at 15:48 UTC ( #930675=perlquestion: print w/replies, xml ) Need Help??
baperl has asked for the wisdom of the Perl Monks concerning the following question:

hi, I am trying to extract data from the sql db to publish it on a website. It prints the header fine, but not the print response section.
sub print_response { unless ($query->param) { print "<b>No data has been submitted</b>"; return; } $sql = "SELECT col1, col2 FROM test ORDER BY col2 desc;"; $sth=$dbh->prepare($sql) or die $dbh->errstr; $sth->execute; print "</td><td>"; print "<table border>"; print "<tr>"; print "<th>col1</th>"; print "<th>col2</th>"; print "</tr>"; while (my $hash_ref = $sth->fetchrow_hashref) { $the_st = $hash_ref->{'col1'}; $the_mc = $hash_ref->{'col2'}; print "<tr><td>$the_st</td><td align=\"right\">$the_mc</td></tr> +"; } print "</table></td></tr></table>"; $sth->finish; }
Can you please let me know where my error is. thanks!

Replies are listed 'Best First'.
Re: post data from db on website
by moritz (Cardinal) on Oct 10, 2011 at 16:11 UTC

    Do you actually call that sub? Where? I don't see the call in your code, that would be an important part to show.

    Did you submit POST parameters?

    Did you view the HTML source of the response? Is the body header there?

      thanks for the questions....yes....I realized I had a typo - missing a double quote :-(
        If possible, use strict; and use warnings; - this should help you avoid many typos.
        Don't use '#ff0000':
        use Acme::AutoColor; my $redcolor = RED();
        All colors subject to change without notice.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://930675]
Approved by moritz
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2018-05-25 02:27 GMT
Find Nodes?
    Voting Booth?