I can't seem to figure out how to return the result to the same page. When I get the result from the database it opens up a new page (search.php) but I want to stay on the same page as the form (the html page) I would greatly appreciate anyone that could be of help.
<html>
<head>
<title>FIND YOUR GID</title>
</head>
<body>
<form action="search.php" method="post">
Search: <input type="text" name="term" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
<script type="text/javascript">
var arrRequiredFields = [ "term" ];
window.onload = function() {
document.forms[0].onsubmit = function() {
for (var i = 0; i < arrRequiredFields.length; i++) {
var field = document.forms[0].elements[arrRequiredFields[i]];
if (field && field.value.length == 0) {
alert("Missing Name of Food");
field.focus();
return false;
}
}
return true;
};
};
</script>
and this is the php
<?php
mysql_connect ("localhost", "","") or die (mysql_error());
mysql_select_db ("");
$term = $_POST['term'];
$sql = mysql_query("SELECT * FROM `Find Your Gid` where Name like '%$term%'");
if (mysql_num_rows($sql) <= 0) {
// no results
echo 'No results found.';
} else
if ($term ="") {
echo 'No name entered!';
} else
echo "<fieldset>";
while ($row = mysql_fetch_array($sql)){
echo '<br/> Name: '.$row['Name'];
echo '<br/> Gid: '.$row['Gid'];
echo '<br/> Giftable: '.$row['Giftable'];
echo '<br/><br/>';
}
echo "</fieldset>";
mysql_close();
?>
I read that I should try this: $_SERVER['PHP_SELF']; instead of search.php But its reading it as url and I get 404 error