I have a form which passes fields $formitem, $keyword, and $type to the following PHP script. The problem is that when the user leaves a field blank, the script interprets it as "all fields". eg if $formitem=015 and $keyword=dog, it will show BOTH item 015 and items with DOG in the text. Similarly, if $keyword is left blank, it returns all records. Snippet of code is below.
Is the problem with the SQL statement, or do I need to use PHP to deal with "empty" variables? Or something completely different?! What I think I need to do is tell the script that if a variable is blank, then ignore it.
Any ideas gratefully appreciated Thanks.
-----------------
Code:
$result = mysql_query("SELECT * FROM tab1 WHERE
((catno='%$formitem%'
OR (text1 LIKE '%$keyword%' OR text2 LIKE '%$keyword%'))
AND section LIKE '%$type%')
AND sold='Unsold'
ORDER BY $order",$db);