Click to go home

This is the website layout




Code for search.pl (called when 'Submit Query' is clicked)

#!perl -w
# $RCSfile: search.pl,v $
# $Revision: 1.1 $
# search products table

use CGI;
use CGI::Carp "fatalsToBrowser";
use DBI;
use Utilities;

$dbh		= "";
$sth		= "";
$user 		= "";
$auth		= "";
$dsn		= "demo";
$driver		= "ODBC";
$found		= 0;
$sql		= << SQL;
SELECT * FROM products WHERE title LIKE ? OR author LIKE ?
SQL

$q		= new CGI;
$search		= $q->param("search");

print($q->header());
print($q->start_html());

if($search eq "")
{
      print("Search field cannot be empty.");
      print($q->end_html());
      exit();
}
if($search !~ /\w{3,}/ || $search =~ /_/)
{
      print("Invalid name, please try again.");
      print($q->end_html());
      exit();
}
if($search =~ /\s/ && $search !~ /^\s/ && $search !~ /\s$/)
{
      print("Sorry, multiple word searches not yet available.");
      print($q->end_html());
      exit();
}

$search =~ s/\s//;
	
$dbh = DBI->connect("dbi:$driver:$dsn",$user,$auth) || die(DBI->errstr);
$sth = $dbh->prepare($sql) || die($dbh->errstr);
$sth->execute("%" . $search . "%","%" . $search ."%") || die($sth->errstr);
print("< table>");
while (@row = $sth->fetchrow())
{
	print(qq(< tr>< td>$row[1]< /td>< td>$row[2]));
	print(qq(< td>< a href="/cgi-bin/add.pl?pid=$row[0]">));
	print(qq(ADD TO CART< /a>< /td>< tr>\n));
	$found++;
}
print("< /table>");

$sth->finish() if $sth;
$dbh->disconnect() if $dbh;

if (!$found)
{
	print("No matches for $search");
}

print($q->end_html());

exit();
Next Page - Add/Update

Jump to:
View Cart  |   Checkout

Go to top