0

so I did a multi filter search in mysqli where you can search using textbox, collection id or type id.

The problem is that when using the search textbox, it returns a

Call to a member function fetch_object() on boolean

But it only returns that error when I type in a string or a single letter. When I type in a digit such as 1 or 2, it works perfectly fine and brings the correct result. Thanks


`
     $whereClauses = array();
   if (! empty($_POST['search'])) $whereClauses[] =       'tblfurniture.product_name ='.'%'.mysql_real_escape_string($_POST['search']).'%';
if (! empty($_POST['collection'])) $whereClauses[] ='tblfurniture.COLID='.mysql_real_escape_string($_POST['collection']);
if (! empty($_POST['type'])) $whereClauses[] = 'tblfurniture.TYPID='.mysql_real_escape_string($_POST['type']);

    $where = '';
     if (count($whereClauses) > 0) {
$where = 'WHERE '.implode(' AND ',$whereClauses);

} $results = $mysqli->query("SELECT * FROM tblfurniture JOIN tblcollection ON tblfurniture.COLID = tblcollection.COLID ".$where);

}

     else {
 $conn = mysqli_connect('localhost', 'root', '', 'hezefurniture');
     // Check connection
   if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
    }
  $results = $mysqli->query("SELECT * FROM tblfurniture 

JOIN tblcollection ON tblfurniture.COLID = tblcollection.COLID ORDER BY tblfurniture.product_id");

} while($row = $results->fetch_object()) {`

Miro
  • 1
  • 1

2 Answers2

0

Your query is returning null value. It seem you are executing wrong query on search textbox , use mysqli_error() to show error .

Prashant Srivastav
  • 1,723
  • 17
  • 28
  • mysql_error() states that when inserting a string, it says that the column of that name does not exist, even though I have specified the column to be tblfurniture.product_name. – Miro Jul 14 '15 at 20:55
  • got to this stage now: Unknown column 'tblfurniture.product_name' in 'where clause' – Miro Jul 14 '15 at 21:13
0

SOLVED:

in

 if (! empty($_POST['search'])) $whereClauses[] = 'tblfurniture.product_name ='.'%'.mysql_real_escape_string($_POST['search']).'%'; 

should be

 if (! empty($_POST['search'])) $whereClauses[] = "tblfurniture.product_name ='%".mysql_real_escape_string($_POST['search'])."%'"; 
Miro
  • 1
  • 1