Home > Backend Development > PHP Tutorial > Why am I getting an \'Incorrect Number of Bind Variables\' Error in My MySQLi Prepared Statement?

Why am I getting an \'Incorrect Number of Bind Variables\' Error in My MySQLi Prepared Statement?

Patricia Arquette
Release: 2024-10-28 07:06:02
Original
403 people have browsed it

Why am I getting an

Incorrect Number of Bind Variables in Prepared Statement: Troubleshooting

When executing an INSERT statement using MySQLi, you may encounter an error indicating that the number of bind variables doesn't match the number of fields in the prepared statement.

This error occurs when attempting to bind results to a statement that does not return any results. To resolve this issue, remove the $stmt->bind_result($user, $pw); line from your code snippet.

The corrected code should look like this:

if($stmt = $conn->prepare("INSERT INTO login(user, pass) VALUES(?, ?)")) {

  /* Bind parameters s - string, b - blob, i - int, etc */
  $stmt->bind_param("ss", $user, $pw);

  /* Execute it */
  $stmt->execute();

  /* Close statement */
  $stmt->close();
  $userId = $conn->insert_id;
} 
Copy after login

The above is the detailed content of Why am I getting an \'Incorrect Number of Bind Variables\' Error in My MySQLi Prepared Statement?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template