-1
$client = $db -> prepare('SELECT CLIENT_ID, CLIENT_NAME FROM client WHERE CLIENT_NAME LIKE "%?%"');
    $query = $_GET['query'];
    $client -> bind_param('s', $query);
    $client -> execute();
    $client -> bind_result($client_id, $client_name);
    while($client -> fetch()){
        $d['suggestions']['value'] = $client_name;
        $d['suggestions']['data'] = $client_id;
    }
    $client -> free_result();

I received the following error in the above statement. Can't see what caused the error.

<b>Warning</b>:  mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement in <b>getclient.php</b> on line <b>15</b><br />
<br />
<b>Notice</b>:  Undefined index: callback in <b>getclient.php</b> on line <b>24</b>

Now I have another error message:

Call to a member function bind_param() on a non-object
halfer
  • 19,824
  • 17
  • 99
  • 186
davidlee
  • 5,611
  • 17
  • 56
  • 82
  • 1
    possible duplicate of [PDO: prepared statement with bindvalue and %](http://stackoverflow.com/questions/4783750/pdo-prepared-statement-with-bindvalue-and) – Sirko Aug 01 '14 at 07:27

1 Answers1

2

You cannot do the LIKE statement like that in regards to percentages.

$client = $db -> prepare('SELECT CLIENT_ID, CLIENT_NAME FROM client WHERE CLIENT_NAME LIKE ?');
$query = $_GET['query'];
$client -> bind_param('s', "%{$query}%");
$client -> execute();
$client -> bind_result($client_id, $client_name);
while($client -> fetch()){
    $d['suggestions']['value'] = $client_name;
    $d['suggestions']['data'] = $client_id;
}
$client -> free_result();`
Simon Fredsted
  • 964
  • 2
  • 14
  • 26