slaterino Posted February 2, 2009 Share Posted February 2, 2009 Howdy, My PHP search engine which was working perfectly well a few hours ago has now stopped working. I'm stumped to know what's wrong with it. It's only a simple search function but looks something like this: $var = @$_GET['qsearch'] ; $trimmed = trim($var); $catalogue_query = "Product_ID, Genus, Common_Name FROM products"; if (isset($_GET['qsearch'])) { $catalogue_query .=" WHERE Common_Name OR Genus like \"%$trimmed%\""; } I'm using an IF query to only use the WHERE clause when the search button has been used. The form part of the search function looks like this: <form name="form" action="catalogue.php" method="get"> <input type="text" name="qsearch" size="15"/> <input type="submit" name="Submit" value="Search" width="6" size="6" height="6"/> </form> When I type any query in then press search it is returning no results. If I leave the box blank and press submit I get all entries. Does anyone know what could be causing this to occur? I would be really grateful for any help! Thanks Russ Link to comment https://forums.phpfreaks.com/topic/143528-solved-php-search-has-stopped-working/ Share on other sites More sharing options...
genericnumber1 Posted February 2, 2009 Share Posted February 2, 2009 Try... <?php $catalogue_query = "SELECT Product_ID, Genus, Common_Name FROM products"; if (!empty($_GET['qsearch'])) { $search = mysql_real_escape_string( trim($_GET['qsearch']) ); $catalogue_query .= " WHERE Common_Name LIKE '%$search%' OR Genus LIKE '%$search%'"; } I added SELECT, if you have that somewhere else, remove it from my code. Link to comment https://forums.phpfreaks.com/topic/143528-solved-php-search-has-stopped-working/#findComment-752950 Share on other sites More sharing options...
slaterino Posted February 3, 2009 Author Share Posted February 3, 2009 Brilliant. That has definately done the trick. Thanks for the help!! Link to comment https://forums.phpfreaks.com/topic/143528-solved-php-search-has-stopped-working/#findComment-753081 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.