I am attempting to update a MySQL database table with new rows from a PHP script. The script is called from a frontend HTML form that gets seralised and passed to the PHP as $_POST variables.
$stmt = $con->prepare("UPDATE blog SET tag = ?, datestamp = ?, title = ?, content = ?, views = ?, shares = ? WHERE id=?");
$stmt->bind_param("ssssiii", $tag, $datestamp, $title, $content, $views, $shares, $postid);
$stmt->execute();
/ Check whether the execute() succeeded
if ($stmt->errno) {
echo "FAILURE! " . $stmt->error;
}
else {
echo var_dump($stmt);
printf("%d Row updated.\n", $stmt->affected_rows);
}
The request does not throw am error, but the database row does not get updated, and it outputs "0 Rows updated". The serialised data is being sent as the right types (strings and ints where appropriate). Does anyone know what might be causing the issue?
echo var_dump($stmt) returns :
object(mysqli_stmt)#2 (9) { ["affected_rows"]=> int(0) ["insert_id"]=> int(0) ["num_rows"]=> int(0) ["param_count"]=> int(7) ["field_count"]=> int(0) ["errno"]=> int(0) ["error"]=> string(0) "" ["sqlstate"]=> string(5) "00000" ["id"]=> int(1) }
echo var_dump($stmt);will return.$postid? And can you confirm that this value exists in the database?/ Check whether the execute() succeededis that a typo?idparameter? Did you try running aSELECTstatement with thatid? I think that this value might not exist, that would explain the output you're receiving.