I am creating a guestbook where the user enter their first name, last name and preference, being PC or Mac. I want it to display only users who have signed the guestbook with the same preference as they selected. For instance if I select PC i want it only to return other guests who selected PC as their preference. The guestbook page is already created along with the database, I'm just struggling with the PHP portion. I will post my code below.



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>My Web</title>
</head>
<body>
<h2 align="left">Who else has your preference?</h2>
<p align="left"><strong>Thanks for signing!</strong></p>
<p align="left">People who share your preference:</p>

<?php
//This program allows the user to specify their preference, PC or Mac, and a list of individuals with the same preference is retrieved from a MySQL database.

//The following four lines of code strip any suspicious content from data submitted through form textbox
//and assign the clean input to variables
//reminder: the name used in $_POST['here'] must be the same as the textbox name in your html form
$fname = strip_tags($_POST['fname']);
$fname = addslashes($fname);
$lname = strip_tags($_POST['lname']);
$lname = addslashes($lname);
$pref = strip_tags($_POST['pref']);
$pref = addslashes($pref);

//Connect to the database server - change username and password to your own (maybe server name too)
mysql_connect("2006.ispace.ci.fsu.edu", "*****", "********** ") or die(mysql_error());

//Connect to my database - change kbaldauf_guests to your database name
mysql_select_db('jmp08c_guests') or die(mysql_error());

//Add user first and last name to the guest_table - change table or field names if yours are different
mysql_query("INSERT INTO guest_table (fname, lname, pref) VALUES('$fname', '$lname', '$pref') ")
or die(mysql_error());

//read all data in the database table into the variable $result
$result = mysql_query("SELECT * FROM guest_table WHERE pref='PC' OR pref='Mac'") or die(mysql_error());

//Output the fname, lname and timestamp fields for each record in the database table stored in $result
while($row = mysql_fetch_array($result)){

if ($pref == PC) {
echo "<p>" . $row['fname'] . " " . $row['lname'] . " " . $row['pref'] ."</p>";
}
elseif ($pref == Mac) {
echo "<p>" . $row['fname'] . " " . $row['lname'] . " " . $row['pref'] ."</p>";
}
else{
echo "<p> Error </p>";
}
}
?>
</body>
</html>