Page 1 of 1
Search Form
Posted: Sun Jan 18, 2009 4:12 pm
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.
Re: Search Form
Posted: Sun Jan 18, 2009 4:20 pm
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'])."%'";
Re: Search Form
Posted: Sun Jan 18, 2009 5:21 pm
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!!!
Re: Search Form
Posted: Sun Jan 18, 2009 6:14 pm
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
}