In this post, you will learn how to build your own search function, allowing your visitors to search through your site using an HTML search form. We are using PHP and MySQL languages. I will hopefully provide you with the most basic and straightforward code available, and feel free to copy and paste this into your own code.
Let’s get started! Here is the first HTML snippet to create a search button and form to accept user input:
<label>Search For: </label><input type="text"
Paste the above code within the body tag and customize it’s look via CSS (See http://www.webdesignerer.wordpress.com/Modern-CSS3-Search-Form/). Now, here is the PHP snippet that will retrieve results from our MySQL database. Save this code on another page with the filename search.php.
// Change the fields below as per the requirements
$db_username="Username used to access database";
$db_password="Password to access database";
$db_name="Database u created for site";
$db_tb_name="Name of the table u created in site database";
$db_tb_atr_name="attribute(column name) of table in which search action is to be performed";
// Now we are going to write a script that will search
// leave the below fields as it is except while loop, which will display
// results on screen
$query_for_result=mysql_query("SELECT * FROM $db_tb_name
You have just created your first search engine! If you found this information useful or if you found any errors in the code, please leave a comment! Also be sure to check out our new facebook page at https://www.facebook.com/pages/The-webdesignerer-Blog/322090944479607!