Here are the two files. One is the html file that has the search box and the other is the php script. Any help would be great.
the html file:
Code: Select all
<html>
<head>
<title>Database Search</title></head>
<BODY BGCOLOR="#FFFFFF" onUnload="nothing()"> <div align="center">
Enter the first three letters of the Postal Code here:<p>
<form action="query.php" method="post">
Postal Code: <input type="text" name="postal_code"><br>
<input type="submit" value="submit" name="submit">
</form>
<BODY>
<html>Code: Select all
#query.php
<?
// connection information
$hostName = "localhost";
$userName = "bob";
$password = "password";
$dbName = "Database";
// make connection to database
mysql_connect($hostName, $userName, $password) or die("Unable to connect to host $hostName");
mysql_select_db($dbName) or die("Unable to select database $dbName");
// Select all the fields in all the records
$query = "SELECT * FROM Database WHERE Postal_Code LIKE '$postal_code%'";
$result = mysql_query($query);
// Determine the number of employees
$number = mysql_numrows($result);
if ($number == 0) {
print "Sorry, there were no records matching those criteria";
} else {
// Print the employee names
for($i=0; $i<$number; $i++){
$name = mysql_result($result,$i,"name");
$address = mysql_result($result,$i, "address");
$city = mysql_result($result, $i, "city");
$province = mysql_result($result, $i, "province");
$postal_code = mysql_result($result, $i, "postal_code");
print "$name, $address, $city,
$province, $postal_code<br>";
}
}
// Close the database connection
mysql_close();
?>Code: Select all
$query = "SELECT * FROM Database WHERE Postal_Code LIKE '$postal_code%'";Code: Select all
$query = "SELECT * FROM Database WHERE Postal_Code LIKE 'P4R%'";