I am working on a site, where I have a search function. I am using a open source search script, phpdig for that. I wanted to know, how can set a default search words using the submit button.I mean, there on the site I have two buttons, one is for normal search when ever some on enter some text in the text box above and clicks on search it will fetch the results.And for the other button, I would like set some default words for search so that when ever some one clicks on
that.automatically the results will be fetched.
Powi's code will create the form for them to enter search words. I recommend you dont put value="bleh" and just leave that off entirely so its a blank textbox.
On the search.php (where you will be routed to once they click the Search button) you need something like the following... (I'm assuming you are using PHP and MySQL... if you use another database lemme know or just read up at www.php.net)
$searchForThis = $_POST['cat'];
$link = mysql_connect('host', 'user', 'password');
die('Could not connect: ' . mysql_error());
mysql_select_db($db , $link) or die("Couldn't open $db:
$result = mysql_query("SELECT * FROM Table WHERE Field LIKE '%$searchForThis%'");
while ($row = mysql_fetch_array($result))
/*same as above but in the SELECT query you can put whatever you want the default query to be... alternatively you can get rid of the if (isset) syntax above and if they don't provide any search criteria it will return all records since all of them will be LIKE an empty string. */