Jump to content

Search script on site...


peterw555

Recommended Posts

Ive got this PHP script searching my SQL database and it references itself to display results etc, but when I hit submit IE errors that it cannot find the page specified... Below is the script, any help would be very appreciated...

<h2>Search</h2>
<form name="search" method="post" action="<?=$PHP_SELF?>">

Seach for: <input type="text" name="find" /> in
<Select NAME="field">

<Option VALUE="serialnumb">Serial Number</option>
<Option VALUE="namemach">Name</option>
<Option VALUE="makemach">Make</option>


</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />


<?

//This is only displayed if they have submitted the form
if ($searching =="yes")
{
echo "<h2>Results</h2><p>";

//If they did not enter a search term we give them an error
if ($find == "")
{
echo "<p>You forgot to enter a search term";
exit;
}

// Otherwise we connect to our Database
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("seewhats") or die(mysql_error());

// We preform a bit of filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);

//Now we search for our search term, in the field the user specified
$data = mysql_query("SELECT * FROM database WHERE ($field) LIKE'%$find%'");

//And we display the results
while($result = mysql_fetch_array( $data ))
{
echo $result['serialnumb'];
echo " ";
echo $result['namemach'];
echo "<br>";
echo $result['makemach'];
echo "<br>";

}

$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}
echo "<b>Searched For:</b> " .$find;
}
?>

</form>

Link to comment
https://forums.phpfreaks.com/topic/36061-search-script-on-site/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.