First on your database you should add a field called ID make it type: int
extra: auto_incrament
and make it primary
so that when you add a contact it will have a unique ID, this way you can display information on wheat/chris instead of wheat/john
now make a page called search.php or what ever and insert the form:
<form method="get" action="search_results.php">
<p><input type="text" name="search" size="20"><input type="submit" value="Submit" name="B1"></p>
</form>
make a page called search_results.php and put in the following code:
$dbhost = "localhost";
$dbusername = "yourusername";
$dbpasswd = "yourpassword";
$database_name = "your data base name";
$connection = mysql_pconnect("$dbhost","$dbusername","$dbpasswd")or die ("Could not connect to MYSQL.");
$db = mysql_select_db("$database_name", $connection)or die("Could not connect to Database.");
$sql = mysql_query("SELECT * FROM contacts WHERE last_name='$search'");
if(mysql_num_rows($sql) > 0) {
// If there are rows, make the table
echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"100%\">
<tr>
<td width=\"25%\" style=\"border-bottom-style: solid\">Last Name</td>
<td width=\"25%\" style=\"border-bottom-style: solid\">First Name</td>
<td width=\"25%\" style=\"border-bottom-style: solid\">Phone #</td>
<td width=\"25%\" style=\"border-bottom-style: solid\"> </td>
</tr>";
while($row=mysql_fetch_array($sql)) {
// adds the lastname then firstname the phone number then link to detail
echo " <tr><td width=\"25%\">".$row['last_name']."</td>
<td width=\"25%\">".$row['first_name']."</td>
<td width=\"25%\">".$row['phone']."</td>
<td width=\"25%\"><a href=\"more_info.php?id=".$row['id']."\">View Detail</a></td></tr>";
}
echo "</table>";
}
now make a file called more_info.php and put in the following code:
$dbhost = "localhost";
$dbusername = "yourusername";
$dbpasswd = "yourpassword";
$database_name = "your data base name";
$connection = mysql_pconnect("$dbhost","$dbusername","$dbpasswd")or die ("Could not connect to MYSQL.");
$db = mysql_select_db("$database_name", $connection)or die("Could not connect to Database.");
$sql = mysql_query("SELECT * FROM contacts WHERE id='$id'");
$result = mysql_fetch_array($sql);
echo " <table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"100%\">
<tr>
<td width=\"50%\">Last Name:</td>
<td width=\"50%\">".$row['last_name']."</td>
</tr>
<tr>
<td width=\"50%\">First Name:</td>
<td width=\"50%\">".$row['first_name']."</td>
</tr>
<tr>
<td width=\"50%\">Phone:</td>
<td width=\"50%\">".$row['phone']."</td>
</tr>
<tr>
<td width=\"50%\">Address:</td>
<td width=\"50%\">".$row['address']."</td>
</tr>
<tr>
<td width=\"50%\">Address 2:</td>
<td width=\"50%\">".$row['address2']."</td>
</tr>
<tr>
<td width=\"50%\">City:</td>
<td width=\"50%\">".$row['city']."</td>
</tr>
<tr>
<td width=\"50%\">State:</td>
<td width=\"50%\">".$row['state']."</td>
</tr>
<tr>
<td width=\"50%\">Zip:</td>
<td width=\"50%\">".$row['zip']."</td>
</tr>
<tr>
<td width=\"50%\">Comments:</td>
<td width=\"50%\">".$row['comments']."</td>
</tr>
</table>";
That should do it! I have not tested the code, but you get the idea.
Chris