...

View Full Version : Search Form Question...



tomyknoker
07-19-2007, 04:44 PM
I have a search form set up... First page is the search fields second page is the results... I really want the whole thing to be together so I thought the best way was just do a php include on the second page for the search page. The only thing is now each time the page loads it runs the search with no fields, so basically outputs everything in the database... Anyone have a better idea of how to do this?

devinemke
07-19-2007, 05:16 PM
<html>
<head>
<title>search</title>
</head>
<body>

<form action="" method="POST">
<input type="text" name="search_term">
<input type="submit" name="submit" value="search">
</form>

<?php
if (isset($_POST['submit']))
{
// do search and display results
}
?>

</body>
</html>

fl00d
07-19-2007, 05:24 PM
well it would help if you could post your code, but I'm pretty sure I understand the problem. A switch statement to see whether the form button has been pressed will do it.

Search_form.inc


<form action=<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Search <input type="text" name="search" />
<input type="submit" value="Search" name="button" />
</form>

The form above can be a separate file and included in the default case or can be echoed in the default case.

Search.php


<?php
switch($_POST['button']){
case "Search":
//code here
break;
default:
include("Search_form.inc");
} //end switch
?>

tomyknoker
07-20-2007, 03:12 AM
Hi guys... I added the above code
if (isset($_POST['submit']))
at the top of the search.php page, then on the results page I have my include but when you run the results page it srtill gives me all the results... any ideas?

fl00d
07-20-2007, 05:33 PM
Post your code...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum