This question already has an answer here:
I have a function that executes a prepared statement. I've pinpointed the problem to the SQL code by wrapping the prepare()
line with an exception catcher, but I can't figure out what is wrong with it.
This is the function
function update_table($column, $value, $conn, $email) {
require "config.php";
$stmtupdate = $conn->prepare("UPDATE $table SET ? = ? WHERE email = ?");
$stmtupdate->bind_param("sis", $column, $value, $email);
$stmtupdate->execute();
$stmtupdate->close();
}
This is one of the function calls
update_table("failedCount", 0, $conn, $email);
Error printed to the page
Fatal error: Uncaught Error: Call to a member function bind_param() on boolean in /var/www/html/usenergy/login.php:125 Stack trace: #0 /var/www/html/usenergy/login.php(218): update_table('failedCount', 0, Object(mysqli), 'testmail@test...') #1 {main} thrown in /var/www/html/usenergy/login.php on line 125
column
is a string that defines the column name where $value will be set to ($value is integer).
</div>