Home >Backend Development >PHP Tutorial >Why does my code throw \'Number of bind variables doesn\'t match number of fields in prepared statement\' when using INSERT?
INSERT - Binding Results from a Non-Resulting Query
The error "Number of bind variables doesn't match number of fields in prepared statement" occurs when attempting to bind results from a prepared statement that does not return any results. In your code snippet, you have included a bind_result call after executing the INSERT statement.
This is incorrect because INSERT is a non-resulting query that does not produce any rows to be bound. Consequently, the bind_result call attempts to bind to non-existent fields, resulting in the error.
To resolve this issue, simply remove the following line from your code:
After removing this line, your code will execute the INSERT statement successfully without encountering the bind variable mismatch error.
The above is the detailed content of Why does my code throw \'Number of bind variables doesn\'t match number of fields in prepared statement\' when using INSERT?. For more information, please follow other related articles on the PHP Chinese website!