Simple PHP Search
Friday June 2, 2006
You can find almost anything on the internet... but how? By searching of course! We all use search engines like Google or Yahoo to find what we need online. On a smaller scale, we often search for products or articles within a very specific site.
One way to have a simply search on your site, is to have all your data contained in a MySQL database. We then use PHP to query the database, and return the results to the user.
One way to have a simply search on your site, is to have all your data contained in a MySQL database. We then use PHP to query the database, and return the results to the user.


Comments
My CMS search function never worked, but I like the software. Have been trying for a long time to find a script tutorial that would help me understand what was happening within the code so I could finally get a search function on my site. THIS ROCKS! I still have some things to do with the script, but this script tutorial gave me a huge leg up!
Many thanks!!!
I think what you’re trying to teach is interesting. Also, just to let you know that I’ve found something called MySearchParser at
http://www.addedworth.com/welcome/MySearchParser.php
which generates the search queries automatically. Also, it supports AND,
OR, NOT and Phrase searches. In short, it allows multiple keyword searches as opposed to single keyword searches.
Thanks for your tutorial. It was very helpful.
i fond error when install it.
Results
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/www/domain.info/index.php on line 39
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/www/domain.info/index.php on line 51
Sorry, but we can not find an entry to match your query
Searched For: example
First of all, I would like to thank you.
I did, excatly you have showed in your page, but myone doesn’t work.
Please help.
Thanks
Hi,
I have also done exactly as it is shown in the tutorial and nothing shows up? no print no error messages nada…
help
Hi,
I’m not getting any error messages, just a blank page after submtting the form, please can some one help. Is it MySQL database messedup? PHP. When I write scripts out of the php book without any forms I get results as soon as i use forms I get error messages unless the code is correct and then i get a blank page.
Someone please e-mail me to offer help, e-mail address mustobaby@googlemail.com
thanks
i used this code but i cant ale to get the results. at the same time i dont get any error too.. please me i need this….
Your Coding gave me a big boost and motivation.It`s easy to understand and up to the level
thank you sooo much
Chanuka
i hape try it your script. but when i click button Search it’s still blank
any 1 can help me
Hi,
i have done what you did in the tutorial but i do not get any results.(i only get blank page) i use wamp and save it as search.php in www directory. should i change my directory? Can you please help?
It keep showing this warning message->
Warning: mysql_fetch_array():
I think it seems not working in actual search query =>$query = “select * from profile where upper($field) like ‘%$find%’ “;
Can anyone please leave the comment or solution for this??
The problem most of you are having (blank page, no results) is caused by the fact that no where in the script is anything catching the POST data from the form and converting it into a variable. To correct this issue, simply insert this code at the very top of your PHP:
// Grab POST data sent from form
$field = @$_POST[’field’] ;
$find = @$_POST[’find’] ;
$searching = @$_POST[’searching’] ;
Everything else in the script “should” work.
Still didnt work for me. I still get nothing at all. Any other suggestions?
Joshua’s solution is right, but if you copy and paste it the symbols around field, find, and searching are not right. Try this one.
$field = $_POST[’field’] ;
$find = $_POST[’find’] ;
$searching = $_POST[’searching’] ;
Hi,
I’ve followed the script to the letter however when i submit the search the form returns itself but there isn’t any results or error messages…
I have checked out the comments and tried adding the fix above but still no joy.
I’m using xampp.
Please help q8-(
Im Not Experienced using mysql or php at all. im only beginning to learn it and i was just looking for tutorial for a search engine, i found this and used it but was wondering how to edit it. If someone is willing to help please reply.
I’m having the same problem as everyone else, Click submit and don’t get any results, and no error.
Even if I leave the field blank, and hit submit i don’t get the warning about not entering anything.
I’ve tried both fixes that were listed earlier, and that didn’t help either.
Does this code just not work?
Thanks
I’ve tried as you say but it doesn’t show anything nor any error or warning message. Please help
I was experiencing the same problems as everyone else here with nothing happening to the script.
1)Change this line form.html
“>
to:
2) Makes sure the form is a html file not php!!eg form.html NOT form.php
3) Drop in this code at the very top of search.php underneath the