Forum Moderators: coopster
When you submit a search the form apparently connects to the database, however it gives a message of "problems..." and does not echo any results. Anyone have any idea what's going wrong here?
HTML Code
---------------
<html>
<head>
<title>TITLE</title>
</head>
<body>
<form action="results.php" method="post">
<div align='center' div id="content">
<h2 align="center">Review Form</h2><br />
Name: <input type=text name="searchname"><br><br>
<p align="center">
<input type="submit" name="search" value="Search">
<input type="reset" name="reset" value="Clear Form">
</p>
</form>
</body>
</html>
PHP Code
---------------
<?
if ($search)
{mysql_connect("localhost", "userID", "password") or die ("Problem connecting to Database");
mysql_select_db ("database");
$srch="%".$search."%";
$query = "select * from TABLE WHERE searchname LIKE '$srch'";
$result = mysql_query($query);
if ($result)
{
echo "Here are the results:<br><br>";
echo "<table width=90% align=center border=0><tr>
<td align=center bgcolor=#00FFFF>Record Number</td>
<td align=center bgcolor=#00FFFF>First Name</td>
<td align=center bgcolor=#00FFFF>Last Name</td>
<td align=center bgcolor=#00FFFF>Month of Birth</td>
<td align=center bgcolor=#00FFFF>Day of Birth</td>
<td align=center bgcolor=#00FFFF>Year of Birth</td>
</tr>";
while ($r = mysql_fetch_array($result)) { // Begin while
$rec = $r["rec"];
$first = $r["firstname"];
$last = $r["lastname"];
$month = $r["mob"];
$day = $r["daybir"];
$year = $r["yob"];
echo "<tr>
<td>$med</td>
<td>$first</td>
<td>$last</td>
<td>$month</td>
<td>$day</td>
<td>$year</td></tr>
<tr> <td colspan=4 bgcolor=\"#ffffa0\">$comment</td>
</tr>";
} // end while
echo "</table>";
} else { echo "problems...."; }
} else {
echo "Search string is empty. <br> Go back and type a string to search";
}
?>
$srch="%".[url=http://us3.php.net/manual/en/function.mysql-real-escape-string.php]mysql_real_escape_string[/url]($search)."%";
It also looks like you are using Register Globals [us3.php.net]. Just be careful with them. Its recommended that you disable that "feature".
:)