View Full Version : A Simple Search Form Not Working

04-15-2007, 02:00 PM
I've set up a simple search form but on POST it get's no result, I've tested it with data I know is definitely in the database, not sure what I am doing wrong...

Search Form

<title>Search Test</title>
<body topmargin="0" leftmargin="0">
<form action="searchResults.php" method="post">
Search Term <input type="text" name="searchterm"><br />
<input type="submit" value="Search">


include 'library/config.php';
include 'library/opendb.php';

/*set varibles from form */
$searchterm = $_POST['searchterm'];
trim ($searchterm);
/*check if search term was entered*/
if (!$searchterm){
echo 'Please enter a search term.';
/*add slashes to search term*/
if (!get_magic_quotes_gpc())
$searchterm = addslashes($searchterm);

/*query the database*/
$query = "SELECT * FROM `tblmembers` WHERE `FirstName` LIKE '&#37;".$searchterm."%' AND `MemberApproved`='A'";
$result = mysql_query($query) or die('Error, query failed'.mysql_error());

/*number of rows found*/
$num_results = $result->num_rows;

echo '<p>Found: '.$num_results.'</p>';
/*loops through results*/
for ($i=0; $i <$num_results; $i++)
$num_found = $i + 1;
$row = $result->fetch_assoc();
echo "$num_found. ".($row['FirstName'])." <br />";

include 'library/closedb.php';