I have been converting the MySQL statements in a few files to use prepared statements using MySQLi.
I have one file where an UPDATE statement fails, even though other INSERT and SELECT statements in the same file work correctly:
if ($type == "inv") {
// add details of email to waiting list record
$comment = "Invitation to " . $class . " emailed on " . date("d/m/Y");
error_log("About to update record " . $wl_id . " with: " . $comment);
$sql = "UPDATE `waitlist` SET wl_changes = CONCAT(wl_changes,?) where wl_ID = ?";
$stmt = $conn->prepare($sql);
if (
$stmt &&
$stmt->bind_param('si', $comment, $wl_id) &&
$stmt->execute()
)
if ($stmt->error) {
error_log("FAILURE!!! " . $stmt->error);
} else {
error_log("Updated {$stmt->affected_rows} rows");
}
$stmt->close();
} else {
error_log($type . " Therefore no update");
}
The PHP log returns:
[13-May-2020 16:20:31 UTC] About to update record 21 with: Invitation to Sat 10am emailed on 13/05/2020
[13-May-2020 16:20:31 UTC] Updated 0 rows
I know that the record with wl_ID of 21 exists because earlier in the file I use it to select details from the record.
Can anyone tell me why it isn’t updating record 21?
Thanks