Forum Moderators: coopster
I have been looking for a little while online for a script that would allow me to create a search box on my website that allows me to search 3 different keyword areas.
I need three search boxes that will search for the same result, i have found nothing online because their is no straight forward tutorial on it.
Many Thanks all
if(isset($_POST['company']))
{
$company = $_POST['company'];
$where = "company = '$company'";
}
if(isset($_POST['state']))
{
$state = $_POST['state'];
if($where == NULL)
{
$where = "$where state = '$state'";
}
else
{
$where = "$where AND state = '$state'";
}
}
if(isset($_POST['city']))
{
$city = $_POST['city'];
if($where == NULL)
{
$where = "$where city = '$city'";
}
else
{
$where = "$where AND city = '$city'";
}
}
$query = "SELECT * FROM tablename where $where";
var $input = Array ('company','state','city');
var $where=$select=NULL;
foreach ($input as $i) {
if (isset($_POST[$i])) {
if ($where) { $where .= " and"; }
$where .= " $i='$_POST[$i]'";
}
}
}
$select = "select * from $table";
if ($where) { $select .= " where $where"; }
TWO THINGS you need to address:
- The above code does not filter $_post[input], do not directly query the database without cleansing.
- The above code uses the same names for input as the fields in the database, do not do this - use an aliasing hash or some method to avoid revealing database field names.