1

While binding variable to my prepared statement PHP reports that the number of parameters do not match !

here is the code:

private $q_setQueue = "update rivr_queues set name='?', description='?' where QueueID='?';";
.
.
.
$stmt = $astdb->prepare($this->q_setQueue);
$stmt->bind_param('sss',$qName,$qDesc,$qID);

number of parameters is three so I think the code is correct.

  • You shouldn't wrap the `?` placeholder with single quotes (`''`) since it would be treated as a real value and not a placeholder. – Ofir Baruch Jun 19 '15 at 07:05

2 Answers2

2

The error you're getting means that the amount of variables you're passing to the bind_param function isn't matching the amount of placeholders you have in your prepared query.

While you do have 3 variables and 3 "question marks" (keep on reading why I used that term and not "placeholders") in the prepared query - notice that when you're wrapping the suppose to be placeholders with single quotes ('') they would be treated as real values and not as placeholders.

So basically, you have 0 placeholders and 3 variables -> no match. Removing the single quotes and updating the query:

private $q_setQueue = "update rivr_queues set name=?, description=? where QueueID=?;";

Should solve your problem.

Ofir Baruch
  • 10,323
  • 2
  • 26
  • 39
-1
$stmt->bind_param(1,$qName);
$stmt->bind_param(2,$qDesc);
$stmt->bind_param(3,$qID);

and omit the single quote on every question mark ?

Sam Teng Wong
  • 2,379
  • 5
  • 34
  • 56