I've written a script (with help!) to search a db by surname; however before the query is submitted the entire db is being displayed below the search box. I want to keep the db hidden and just pull out the relevant results, any help would be greatly appreciated! the script I'm using is:
<form method="post" name="Search" action="test2.php">
<input type="text" name="name" autocomplete="OFF" />
<input value="Search" type="submit" name="Search" />
<input value="yes" type="hidden" name="submitted" />
</form>
<?php
if($_POST['submitted'] == 'yes')
$username="**";
$password="";
$database="***";
$server="localhost";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle) or die( "Unable to select database");
$query="SELECT FROM **** WHERE surname LIKE '" . mysql_real_escape_string($_POST['name']) . "%'";
$result=mysql_query($query) or die ('<br>Query string: ' . $SQL . '<br>Produced error: ' . mysql_error() . '<br>');
if (mysql_num_rows($result) == 0) {
echo "No results found";
exit;
}
$num=mysql_numrows($result);
$fields_num = mysql_num_fields($result);
echo "<h1>Table: {$table}</h1>";
echo "<table border='1'><tr>";
for($i=0; $i<$fields_num; $i++)
{
$field = mysql_fetch_field($result);
echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
while($row = mysql_fetch_row($result)){
echo "<tr>";
foreach($row as $cell)
echo "<td>$cell</td>";
echo "</tr>\n";
}
mysql_free_result($result);
mysql_close($db_handle);
?>