Search results
Click here to go back to the search page.";
// remove whitespace from user input
$name = trim($name);
// if user input is empty, give error message and exit
if (!$name) {
echo "No search term given.";
echo $link;
exit;
}
// connect to database and select database 'std'
$db = mysql_connect("localhost");
mysql_select_db("std", $db);
// find all records in 'stdtb1' table where data in the 'stdnames' field
// contains the string input by the user on the SearchForm.html page
$query = "SELECT stdtb1 FROM stdtb1 WHERE stdname LIKE '%".$sname."%'";
$result = mysql_query($query);
// if no results are returned from the query, give error message and exit
if (mysql_num_rows($result) == 0) {
echo "Sorry, no matching results.";
echo $link;
exit;
}
// return the data and display it
while ($record = mysql_fetch_assoc($result)) {
while (list($fieldname, $fieldvalue) = each ($record)) {
echo $fieldname.": ".$fieldvalue."
";
}
echo "
";
}
// include the hyperlink to SearchForm.html
echo $link;
?>