Skip to content
Advertisement

PHP – mysqli_stmt_execute() always returns false

Good afternoon,

I am building a calculator, using JS and PHP, and need to INSERT the results and other things to a database.

I am using prepared statements to achieve that, but for some reason, I am unable to INSERT anything, as mysqli_stmt_execute() is always returning false.

JavaScript

This is how I did it (still need a few checks to add the IP if it doesn’t exist). It does everything without a problem until if (mysqli_stmt_execute($stmt2)) returns false, so it doesn’t add anything to the DB.

Am I missing something here?

EDIT:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?,?,?,?,?,?)' at line 1 I wrote this:

JavaScript

before the execute.

Advertisement

Answer

The problem is that you’re closing the statements and links in the loop, so you can’t reuse them as the loop repeats.

But you don’t need any of this looping, it can be done entirely with one query that inserts the result of SELECT.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement