Search Form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
olly79
Forum Newbie
Posts: 3
Joined: Sun Jan 18, 2009 4:09 pm

Search Form

Post by olly79 »

Hi all,

Just wondering if someone can help me with the following:

I have a site for which I want to add a search box; whereby which users can search for people based on the following criteria: Name/Pin/Keyword

I'm new to PHP and MySQL; therefore any help will be much appreciated.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Re: Search Form

Post by Burrito »

Code: Select all

 
$query = "SELECT * FROM `someTable` WHERE `name` LIKE '".mysql_escape_string($_POST['searchField'])."%' OR `pin` LIKE '".mysql_escape_string($_POST['searchField'])."%' OR `keyword` LIKE '".mysql_escape_string($_POST['searchField'])."%'";
 
olly79
Forum Newbie
Posts: 3
Joined: Sun Jan 18, 2009 4:09 pm

Re: Search Form

Post by olly79 »

Hi,

I needed it taking down to the basics.

I need to add the search box and the necessary fields to the HTML and from there I'm not sure of what I need to do next.

Do I need to create a file for the MySQL db? and then how does that translate to the search form?

Thanks and sorry for the numpty questions!!!
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Re: Search Form

Post by Burrito »

Code: Select all

 
<form method="post">
<input type="text" name="searchField">
<input type="submit" value="search">
 
create a mysql table with the three fields in that query I posted above

Code: Select all

 
<?php
if(isset($_POST['search']))
{
  // use the query I gave you before
}
 
Post Reply