Home >Backend Development >PHP Tutorial >Why am I getting an \'Incorrect Number of Bind Variables\' Error in My MySQLi Prepared Statement?
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; }
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!