
Alaskan5
Novice
Jul 23, 2013, 5:30 PM
Post #1 of 3
(23958 views)
|
Perl CGI script Mysql Help
|
Can't Post
|
|
I'm having an issue connecting to the database or maybe it's the query? But when this script is executed I receive a blank page without results. I greatly appreciate if you could look over this. Database name: perltest table name: schedule Columns: name(varchar),day(varchar),number(int)
#!"C:\xampp\perl\bin\perl.exe #use statements use CGI; use DBI; my $q=new CGI; #declaration my $sth; my $sql; my $sn; my $name; my $day; my $number; my @data; #make the page output print $q->header( "text/html" ), $q->start_html( -title => "Printing the table", -bgcolor => "#ffffff" ), $q->p(" The following data is provided" ), $q->end_html; # HTML for the start of the table print "<table border=\"1\" with=\"800\">\n"; # print table columns headers print "<tr><td>Name</td><td>Day</td><td>Number</td></tr>\b"; #connect to the database my $dbh = DBI->connect('DBI;mysql:perltest','root','password',{RaiseError=>1}); #prepare statements my $query = qq{ select * from schedule}; $sth = $dbh->prepare($query); #execute the data insert $sth->execute(); #retrieve the values returned from SQL statements while (@data = $sth->fetchrow_array()) { $name = $data[0]; $day = $data[1]; $number = $data[2]; #print table rows print "<tr><td>$name</td><td>$day</td><td>$number</td></tr>\n"; } # close table print "</table>\n"; #disconnect $dbh->disconnect();
|