#!perl use DBI; use CGI; print "Content-Type: text/html\n\n"; $head = <<'HEAD'; Branch Inventory Lookup HEAD $tail = <<'TAIL'; TAIL $body = <<'BODY';

Branch Inventory Query

div>
BODY $results = <<'RESULTS';
RESULTS $i = 0; $c = new CGI(); $searchTerm = $c->param("searchTerm"); $likeEquals = $c->param("likeEquals"); $field = $c->param("field"); $searchTerm =~ s/'/\\'/; $likeEquals =~ s/'/\\'/; $field =~ s/'/\\'/; if($searchTerm eq "") { $searchTerm = "void"; } $h = DBI->connect("dbi:mysql:inventory:localhost","ID","PW") or die("couldnt connect to database"); $query = "SELECT SerialNumber, AssetTag, AssetType, Branch, Status, Comments FROM assets WHERE $field $likeEquals ? ORDER BY AssetType"; $q = $h->prepare($query); $rows = $q->execute($searchTerm); %columns = ( SerialNumber => "Serial Number", AssetTag => "Asset Tag", AssetType => "Asset Type", Branch => "Branch", Status => "Status", Comments => "Comments", ); if($rows > 0) { $results .= ""; $results .= ""; foreach $field (@{$q->{NAME}}) { $results .= ""; } $results .= ""; if($c->param("searchTerm")) { while ($row = $q->fetchrow_hashref) { if($i % 2 == 0) { $results .= ""; } else { $results .= ""; } $i++; } } } else { $results .= "No results matched your Inventory query."; } $h->disconnect(); $results .= <<'RESULTS';
Your search for $searchTerm in $columns{$field} returned $rows result(s).
$columns{$field}
$row->{SerialNumber}$row->{AssetTag}$row->{AssetType}$row->{Branch}$row->{Status}$row->{Comments}
$row->{SerialNumber}$row->{AssetTag}$row->{AssetType}$row->{Branch}$row->{Status}$row->{Comments}
RESULTS print $head; print $body; print $results; print $tail;