in reply to Returning values from mysql with cgi

I assume you can fix this from the replies to your previous posts. As you code gets more complex, you will find it easier to debug if you organise the code as far as possible into logical self contained blocks e.g. separate the data preparation from the data display. The odd comment line helps too. Like this

use strict; use warnings; use diagnostics; use CGI qw(standard); #use CGI::Carp 'fatalsToBrowser'; use DBI(); use DBD::mysql; # input parameters my $q = CGI->new; my $name = $q->param('name'); # prepare data my $dbh = DBI->connect('dbi:mysql:oncall','webuser','password') or die "Connection Error: $DBI::errstr"; my $sql = 'SELECT name,day,phone FROM users WHERE name = ?'; my $sth = $dbh->prepare($sql); $sth->execute($name); my ($name, $day, $phone) = $sth->fetchrow_array(); $sth->finish(); $dbh->disconnect(); # display data print $q->header; print $q->start_html( -title=>'Users Schedules' ); # use here-doc for html print <<HTML; <h1>Users Schedules</h1> <table border="3" cellpadding="5"> <tr> <th>Name</th> <th>On-Call</th> <th>Phone Number</th> </tr> <tr> <td>$name</td> <td>$day</td> <td>$phone</td> </tr> </table> HTML # if the result is not what you expected # add a debug line to show what the # database is being asked to do print "<hr/><tt>SQL=[$sql] : ?=[$name]</tt>"; print $q->end_html;
poj