I wanted to make a search engine for my e-library and i had 3 fields that if the user submit one of them or 2 of them or all 3 off them,it will do a correct query..
I already try to do this but when just one of the filed is blank ex. author, i get an error..
I had 3 fields :
1. Keyword
2. File Name
3. Author
<?php
$sql ="SELECT * ";
$sql .="FROM tbl_keyword ";
$sql .="WHERE ";
if ($keyword != "")
{
$sql .="keyword LIKE '%$keyword%'";
}
if ($author != "")
{
$sql .=" OR author LIKE '%$author%'";
}
if ($namefile != "")
{
$sql .=" OR namefile LIKE '%$namefile%'";
}
if ($keyword == "" && $author == "" && $namefile == "")
{
header("Location: index.php");
exit ();
}
?>
I wanted to know how should i do this or is there a simple coding for it..could anybody help me please :-)
thanks be 4.