1. Home
  2. Computing & Technology
  3. PHP / MySQL
photo of Angela Bradley

Angela's PHP / MySQL Blog

By Angela Bradley, About.com Guide to PHP / MySQL

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.

Comments

July 4, 2006 at 9:37 pm
(1) seraaj says:

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!!!

January 24, 2007 at 9:16 pm
(2) Jerry says:

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.

April 14, 2007 at 2:39 pm
(3) Joe says:

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

November 1, 2007 at 9:00 pm
(4) Nihat says:

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

November 14, 2007 at 10:26 am
(5) anne says:

Hi,
I have also done exactly as it is shown in the tutorial and nothing shows up? no print no error messages nada…
help

November 18, 2007 at 3:28 pm
(6) Wayne says:

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.

November 18, 2007 at 3:29 pm
(7) Waynr says:

Someone please e-mail me to offer help, e-mail address mustobaby@googlemail.com

thanks

February 8, 2008 at 1:40 am
(8) suresh says:

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….

February 15, 2008 at 10:04 am
(9) Chanuka says:

Your Coding gave me a big boost and motivation.It`s easy to understand and up to the level

thank you sooo much

Chanuka

February 20, 2008 at 12:52 pm
(10) boys says:

i hape try it your script. but when i click button Search it’s still blank :(
any 1 can help me

February 27, 2008 at 5:37 am
(11) Ozy says:

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?

May 12, 2008 at 10:01 pm
(12) uk says:

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??

May 28, 2008 at 5:28 pm
(13) Joshua says:

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. :-)

May 30, 2008 at 11:24 pm
(14) Hampy says:

Still didnt work for me. I still get nothing at all. Any other suggestions?

June 2, 2008 at 1:17 pm
(15) Patrick says:

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’] ;

July 29, 2008 at 8:53 am
(16) Tony says:

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-(

July 29, 2008 at 6:22 pm
(17) Mark says:

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.

July 30, 2008 at 4:12 pm
(18) Chris says:

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

August 2, 2008 at 8:58 am
(19) Sakya Somnath Das says:

I’ve tried as you say but it doesn’t show anything nor any error or warning message. Please help

September 11, 2008 at 11:00 am
(20) Ev says:

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

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

Explore PHP / MySQL

More from About.com

  1. Home
  2. Computing & Technology
  3. PHP / MySQL

©2008 About.com, a part of The New York Times Company.

All rights reserved.