Hi,
I have an HTML form that is to query MySQL database and output results.
The user is to choose the column name and then type in a search term. The script is to find anything similar (not exact, but similar since i am using "like" of SQL) and output.
When I run the form, I do not get any results whatsoever. It goes to the results.php page and nothing appears on the webpage.
I tried messing with the SQL and the PHP but couldn't get it to work.
Thoughts?
Here is HTML form;
<form action="results.php" method="post">
Choose Search Type:
<br>
<select name="searchtype">
<option value="LastName">Last Name</option>
<option value="FirstName">First Name</option>
<option value="CurrPhone">Phone Number</option>
</select>
<br>
Enter Search Term:
<br>
<input name="searchterm" type=text size="40" maxlength="40">
<br>
<input type=submit value="submit" name="submit">
</form>
Here is PHP script:
<?
trim($searchterm);
if (!$searchtype || !$searchterm)
{
echo "You have not entered search details. Please go back and try again.";
exit;
}
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
@ $db = mysql_pconnect("localhost", "", ""
;
if (!$db)
{
echo "Error: Could not connect to database. Please try again later.";
exit;
}
mysql_select_db("hms2003"
;
$query = "select * from personal where ".$searchtype." like '%".$searchterm."%'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo "<p>Number of entries found: ".$num_results."</p>";
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "<p><strong>".($i+1).". Last Name: ";
echo htmlspecialchars( stripslahes($row["LastName"]));
echo "</p>";
}
?>
Any thoughts would be greatly appreciated.
I have an HTML form that is to query MySQL database and output results.
The user is to choose the column name and then type in a search term. The script is to find anything similar (not exact, but similar since i am using "like" of SQL) and output.
When I run the form, I do not get any results whatsoever. It goes to the results.php page and nothing appears on the webpage.
I tried messing with the SQL and the PHP but couldn't get it to work.
Thoughts?
Here is HTML form;
<form action="results.php" method="post">
Choose Search Type:
<br>
<select name="searchtype">
<option value="LastName">Last Name</option>
<option value="FirstName">First Name</option>
<option value="CurrPhone">Phone Number</option>
</select>
<br>
Enter Search Term:
<br>
<input name="searchterm" type=text size="40" maxlength="40">
<br>
<input type=submit value="submit" name="submit">
</form>
Here is PHP script:
<?
trim($searchterm);
if (!$searchtype || !$searchterm)
{
echo "You have not entered search details. Please go back and try again.";
exit;
}
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
@ $db = mysql_pconnect("localhost", "", ""
if (!$db)
{
echo "Error: Could not connect to database. Please try again later.";
exit;
}
mysql_select_db("hms2003"
$query = "select * from personal where ".$searchtype." like '%".$searchterm."%'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo "<p>Number of entries found: ".$num_results."</p>";
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "<p><strong>".($i+1).". Last Name: ";
echo htmlspecialchars( stripslahes($row["LastName"]));
echo "</p>";
}
?>
Any thoughts would be greatly appreciated.