Can someone tell me why this script prints correctly from the command line, but won't display in a browser? It cuts off after the SQL statement is prepared.
#!/usr/bin/perl use DBI; use CGI; my $col1; my $col2; my $col3; # Print HTML headers, etc. $cgi = new CGI; print $cgi->header; print $cgi->start_html(); # Open a connection %attr = (PrintError => 0, RaiseError => 0); $dbh = DBI->connect("dbi:DB2:CDWP", "xxxx", "XXXX", \%attr); # Prepare SQL statement $sql = "SELECT * FROM delete.metadata"; $sql.= " FETCH FIRST 10 ROWS ONLY"; # Execute SQL against CDW connection $sth = $dbh->prepare($sql); $sth->execute(); # Bind results to local variables $sth->bind_col(1,\$col1); $sth->bind_col(2,\$col2); $sth->bind_col(3,\$col3); # Print results print $cgi->table(); while ($sth->fetch) { print "<tr><td>$col1</td><td>$col2</td></tr>\n"; } # Clean up $dbh->disconnect(); print $cgi->end_table; print $cgi->end_html; exit;
Here's the output from the command line (correct):
Content-Type: text/html; charset=ISO-8859-1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +" /> </head> <body> <table /><tr><td>Loan</td><td>Attribute</td></tr> <tr><td>Loan</td><td>Attribute</td></tr> <tr><td>Loan</td><td>Attribute</td></tr> <tr><td>Loan</td><td>Attribute</td></tr> <tr><td>Loan</td><td>Attribute</td></tr> <tr><td>Loan</td><td>Attribute</td></tr> <tr><td>Loan</td><td>Attribute</td></tr> <tr><td>Loan</td><td>Attribute</td></tr> <tr><td>Loan</td><td>Attribute</td></tr> <tr><td>Loan</td><td>Attribute</td></tr> </table> </body> </html>
And in the browser...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +" /> </head> <body>
Where's the rest of my output!?

In reply to Output of CGI with DBI by brp4h

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.