Chris
Chris

Reputation: 1416

mysqli_stmt::bind_param Number of variables doesn't match number of parameters in prepared statement

This is my function which creates the prepared statement:

function query($query, $values_array) {

if ($stmt = $link->prepare($query)) {

    for ($i = 1; $i < count($values_array); $i++) {
     if (!$stmt->bind_param($values_array[0][$i-1], $values_array[$i])) {
        return false;
     }
    }

if (!$stmt->execute()) {
    return false;
}
$result = $stmt->get_result();
$stmt->close();
}

return $result;
}

$query is

insert into table (var1, var2, var3, var4, var5, var6) values (?, ?, ?, ?, ?, ?)

$values_array is

array(7) {
[0]=>
string(6) "diisii"
[1]=>
float(9)
[2]=>
int(1)
[3]=>
int(1)
[4]=>
string(5) "now()"
[5]=>
int(1)
[6]=>
int(1)
}  

I cannot figure out the problem as this error is only thrown when binding params to an insert statement. Select statements work without problems!

Upvotes: 2

Views: 1642

Answers (0)

Related Questions