Jump to content

[SOLVED] PHP Search has stopped working


slaterino

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.