#!c:/ActivePerl/bin/perl.exe

use DBI;
use CGI qw(:standard);

print header, start_html(-title=>"Team Lookup",-BGCOLOR=>"#66ff33");
print start_form,"<font face='arial' size='+1'>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.<br>";
         exit;
    }
    print h2("Data for \u$team");
    while(($name,$salary,$age) = $sth->fetchrow_array()){
        print <<EOF;
            <table border="1">
               <tr>
                   <th>Name</th>
                   <th>Salary</th>
                   <th>Age</th>
               </tr>
               <tr>
                   <td>$name</td>
                   <td>$salary</td>
                   <td>$age</td>
               </tr>
            </table>
          EOF
          print end_html();
          $sth->finish();
          $dbh->disconnect();
    }
}