Hi,
This my be of help, it is my working code
========== find-a.php===========
<HTML>
<head>
<title>Search Users</title>
</head>
<BODY>
<form action="find-b.php" method="post">
<P>FIRST NAME:
<SELECT name="first">
<?php
$db = mysql_connect("localhost", "user", "password")
or die ("cant connect to the DB");
mysql_select_db("test",$db);
// create SQL statement
$query = "SELECT distinct first FROM employees ORDER BY first";
// execute SQL query and get result
$res1 = mysql_query($query,$db)
or die("Couldn't execute query.");
// put data into drop-down list box
while ($row = mysql_fetch_array($res1)) {
$firstname = $row["first"];
echo "<OPTION value=\"$firstname\">$firstname</OPTION>";
}
?>
</SELECT>
<P>LAST NAME:
<SELECT name="last">
<?php
// create SQL statement
$query = "SELECT distinct last FROM employees ORDER BY last";
// execute SQL query and get result
$res2 = mysql_query($query,$db)
or die("Couldn't execute query.");
// put data into drop-down list box
while ($row = mysql_fetch_array($res2)) {
$lastname = $row["last"];
echo "<OPTION value=\"$lastname\">$lastname</OPTION>";
}
?>
</SELECT>
<P>DEPARTMENT:
<SELECT name="dept">
<?php
// create SQL statement
$query = "SELECT distinct dept FROM employees";
// execute SQL query and get result
$res3 = mysql_query($query,$db)
or die("Couldn't execute query.");
// put data into drop-down list box
while ($row = mysql_fetch_array($res3)) {
$dept = $row["dept"];
echo "<OPTION value=\"$dept\">$dept</OPTION>";
}
?>
</SELECT>
<INPUT type="submit" value="Find">
</FORM>
</BODY>
</html>
==============find-b.php==========
<?php
$db = mysql_connect("localhost", "user", "password")
or die ("cant connect to the DB");
print ("You have connected to database successfully");
?><br><br><?php
echo date("D M d, Y", time());
?><br><br><?php
mysql_select_db("test",$db);
$first = $POST['first'];
$last = $POST['last'];
$dept = $_POST['dept'];
echo "Find user<b>$first $last</b><p>\n\n";
if($first && !$last)
$query = "SELECT FROM employees WHERE first = '".mysql_escape_string($first)."' ORDER BY first";
else if (!$first && $last)
$query = "SELECT FROM employees WHERE last = '".mysql_escape_string($last)."' ORDER BY first";
else if($first && $last)
$query = "SELECT FROM employees WHERE first = '".mysql_escape_string($first)."' AND last = '".mysql_escape_string($last)."' ORDER BY first";
else if ($dept)
$query = "SELECT FROM employees WHERE dept = '" . mysql_escape_string($dept) . "' ORDER BY first";
else
$query = "SELECT * FROM employees";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
echo "There are $numrows user(s) in the database, they are";
?><br><br><?php
echo "<table border=1><tr class='left'><td width='300'>\n";
echo "<tr><td>Name</td><td>e-mail</td><td>Department</td><td>Photo</td></tr>\n";
while ($myrow = mysql_fetch_row($result)) {
printf("<tr><td>%s %s</td><td>%s</td><td>%s</td><td>
%s</td>\n",
$myrow[1], $myrow[2],$myrow[3], $myrow[4], $myrow[5]);
}
echo "</table>\n";
//
?>
</html>