#!c:/ActivePerl/bin/perl.exe
use DBI;
use CGI qw(:standard);
print header, start_html(-title=>"Team Lookup",-BGCOLOR=>"#66ff33");
print start_form,"Look up what name? ",textfield('name'),p;
print submit, end_form, hr;
if(param()) {
$team = param('name');
$dbh = DBI->connect("DBI:mysql:host=localhost;database=sample_db;user=root;password=") or print "Connection failed: ". $DBI::errstr;
$sth=$dbh->prepare("SELECT name, salary, age FROM teams where name = ?");
$sth->execute($team);
if ($sth->rows == 0){
print "Your team isn't in the table.
";
exit;
}
print h2("Data for \u$team");
while(($name,$salary,$age) = $sth->fetchrow_array()){
print <
Name
Salary
Age
$name
$salary
$age
EOF
print end_html();
$sth->finish();
$dbh->disconnect();
}
}