# already connected to database
print $cgi->start_form (-method => "POST");
print $cgi->textfield (-name => "plate",
-value => $plate,
-size => 40);
print $cgi->submit (-name => "button", -value => "Search");
print $cgi->end_form ();
# run a search if a keyword was specified
search_members ($plate) if $plate;
# MAIN-BODY
print $cgi->end_html ();
$dbh->disconnect ();
exit (0);
# SEARCH_MEMBERS
sub search_members
{
my ($plate) = shift;
my ($sth, $count);
printf "Search results for keyword: %s
\n",
$cgi->escapeHTML ($plate);
$sth = $dbh->prepare (qq{
SELECT * FROM plate WHERE genomic_dna_id LIKE ?
});
$sth->execute ("%" . $plate . "%");
$sth = $dbh->prepare (qq{
SELECT * FROM plate WHERE plate_id LIKE ?
});
# look for string anywhere in name field
# the search is performed by adding the % wildcard charcter to both ends of the keyword so it can be found anywhere in the fname column.
$sth->execute ("%" . $plate . "%");
$count = 0;
# fetchrow_hashref returns a reference to a hash containing column values for the next row of the result set
while (my $hash_ref = $sth->fetchrow_hashref ())
{
format_html_entry ($hash_ref);
++$count;
}
print $cgi->p ("$count entries found");
}
sub format_html_entry
{
my ($entry_ref) = shift;
my ($address);
# encode characters that are special in HTML
foreach my $key (keys (%{$entry_ref}))
{
$entry_ref->{$key} = $cgi->escapeHTML ($entry_ref->{$key});
}
printf "Name: %s
\n", format_name ($entry_ref);
print "Plate_id: $entry_ref->{plate_id}
\n" if $entry_ref->{plate_id};
print "Template_id: $entry_ref->{template_id}
\n" if $entry_ref->{template_id};
print "Genomic_dna_id: $entry_ref->{genomic_dna_id}
\n" if $entry_ref->{genomic_dna_id};
print "Expiry date: $entry_ref->{expiry_date}
\n" if $entry_ref->{expiry_date};
print "Barcode_ID: $entry_ref->{barcode_id}
\n" if $entry_ref->{barcode_id};
}