uneeb
uneeb

Reputation: 89

mysqli_stmt::bind_result(): Number of bind variables doesn't match number of fields in prepared statement in

I am using a prepared statement I have passed exactly the same amount of variable in bind_param as I am expecting but still it is giving me an error of variable count doesn't match.

$query = "select `shipping_name`,`shipping_address1`,`shipping_address12`,`shipping_city`,`shipping_state`,`shipping_postalcode`,`billing_name`,`billing_address2`,`billing_address22`,`billing_city`,`billing_state`,`billing_postalcode` from puppy_shipping where unique_id=?";
$stmt = $db->prepare($query);
$bind = 'ssssssssssss';
if ($stmt) {
    $stmt->bind_param('s', $id);
    $stmt->execute();
    $stmt->bind_result($bind, $shipping_name, $shipping_address1, $shipping_address12, $shipping_city, $shipping_state, $shipping_postalcode, $billing_name, $billing_address2, $billing_address22, $billing_city, $billing_state, $billing_postalcode);
    while ($stmt->fetch()) {
    }
    $stmt->close();
}

Upvotes: 2

Views: 1463

Answers (2)

user12650351
user12650351

Reputation: 1

Object oriented style

$stmt->bind_result($name, $code);

Procedural style

mysqli_stmt_bind_result($stmt, $name, $code);

Upvotes: 0

Qirel
Qirel

Reputation: 26450

Your problem is with this line

$stmt->bind_result($bind, $shipping_name,$shipping_address1,$shipping_address12, ....);

You're trying to bind the variable-types, like you do with bind_param(), which is wrong - because this function does not have a parameter like that. bind_result()s only arguments are the values you select from the query, nothing else.

The solution is to simply remove $bind from your bind_result() call, making it

$stmt->bind_result($shipping_name, $shipping_address1, $shipping_address12, ....);

Reference

Upvotes: 3

Related Questions