#!/usr/local/bin/perl use DBI; use CGI; use CGI::Carp qw(fatalsToBrowser); $buffer = $ENV{'QUERY_STRING'}; @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } ##Start database connections#################################################### $database = "database"; $db_server = "localhost"; $user = "user"; $password = "password"; ##Connect to database, insert statement, & disconnect ########################## $dbh = DBI->connect("DBI:mysql:$database:$db_server", $user, $password); $statement = "SELECT city FROM database WHERE $FORM{state}"; $sth = $dbh->prepare($statement) or die "Couldn't prepare the query: $sth->errstr"; $rv = $sth->execute or die "Couldn't execute query: $dbh->errstr"; $rc = $sth->finish; $rc = $dbh->disconnect; ################################################################################ print "Content-type: text/html\n\n"; #*******************************************Print to the first half of page print < xxx

$FORM{state} x

EOF #********************************************** Stop printing the first half of the page $x=1; while (@row = $sth->fetchrow_array;) { print < EOF $x=x+4; } print <
$row[$x]
$row[$x+2]
$row[$x+3]
$row[$x+4]

 

EOF