So I need to return a single line of data in a table called users, it must be based on the name that is inputted through the html page. I must return it into this table. At one point I had it just returning the name but now it just displays the table without error. I'm a new aspiring perl programmer doing this for a term project and trying to go the extra mile. Heres my code.
#!/usr/bin/perl -w
use CGI qw(standard);
use DBI();
use DBD::mysql;
use warnings;
use diagnostics;
my $q = CGI->new;
my $name = $q->param('name');
my $dbh = DBI->connect('dbi:mysql:oncall','webuser','password')
or die "Connection Error: $DBI::errstr\n";
my $sth = $dbh->prepare('Select * from users where name = "$name"'
+);
$sth->execute();
print $q->header;
print $q->start_html;
print "<HTML>\n<HEAD>\n<TITLE>Users scheduled</title>\n</head>\n<B
+ody bgcolor=white\n";
print "<h1>Users Schedules</h1>\n";
print "<Table border= 3>\n";
print "<TR><TH> Name</TH>><TH>On-Call</TH>><TH>Phone Number</th>\n
+";
my ($name, $day, $phone) = $sth->fetchrow_array();
print "<tr><td>$name</td><td>$day</td><td>$phone</td>\n";
print "</table></body></html>\n";
$sth->finish();
$dbh->disconnect();
exit;
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.