mysqli prepared statements UPDATE throwing error message

Codes here !

Moderators: macek, egami, gesf

Post Reply
johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: mysqli prepared statements UPDATE throwing error message

Post by johnj » Fri Aug 16, 2013 9:16 pm

Looks like you are violating the basic idea behind "bind" function. If you create place holders for 4 variables and if you supply or bind ONLY 3 or less than 3 then you will get the warning saying that "Number of bind...".

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: mysqli prepared statements UPDATE throwing error message

Post by johnj » Fri Aug 16, 2013 9:24 pm

Try to rearrange the code like this:

Code: Select all

$stmt->execute();
$x = call_user_func_array(array($stmt, 'bind_result'), &$bindParams);
  if (false === $x) {die('bind_param()error :' . $mysqli->error);}
$stmt->close();

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: mysqli prepared statements UPDATE throwing error message

Post by johnj » Fri Aug 16, 2013 9:33 pm

The other thing that you can try is to change:

Code: Select all

$x = call_user_func_array(array($stmt, 'bind_result'), &$bindParams);
to

Code: Select all

$stmt->bind_result(&$Address, &$Permit_Rate);
Make a direct call using bind_result instead of using call_user_func()

mash
New php-forum User
New php-forum User
Posts: 7
Joined: Sat Jan 14, 2012 1:36 pm

Re: mysqli prepared statements UPDATE throwing error message

Post by mash » Sun Oct 13, 2013 8:01 am

The problem is that there is actually missing one parameter.
The array containing your bind params needs to have the first element set to the type of the variables in question.
so: UPDATE customers set name=? where id=?
requires an array of three fields for putting to bind_params
a[0]='si';//for string and integer
a[1]=$newName;
a[2]=$customerID;

You don't have to worry bout the field-types and can set everything to string (='s') and the rest will be done automagically.
Easier: If you have 5 fields with params you just set:
a[0]=str_repeat('s',5);

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests