Home >Backend Development >PHP Tutorial >Why Does \'Number of Bind Variables Doesn\'t Match Number of Fields in Prepared Statement\' Error Occur During INSERT Queries?

Why Does \'Number of Bind Variables Doesn\'t Match Number of Fields in Prepared Statement\' Error Occur During INSERT Queries?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-31 04:12:02557browse

 Why Does

Number of Bind Variables Doesn't Match Number of Fields in Prepared Statement while Inserting Data

When attempting to insert data into a database using PHP's mysqli extension, you may encounter the following error:

Warning: mysqli_stmt::bind_result(): Number of bind variables doesn't
match number of fields in prepared statement in
E:\XAMPP\htdocs\account\lib\register.php on line 73

This error occurs when you specify a bind variable for each field in the INSERT query, but the query does not return any results. To resolve this issue, you need to remove the line that binds the results:

<code class="php">$stmt->bind_result($user, $pw);</code>

The modified code snippet would look like this:

<code class="php">$conn->prepare("INSERT INTO login(user, pass) VALUES(?, ?)");
$stmt->bind_param("ss", $user, $pw);
$stmt->execute();</code>

The above is the detailed content of Why Does \'Number of Bind Variables Doesn\'t Match Number of Fields in Prepared Statement\' Error Occur During INSERT Queries?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn