An UPDATE query is used to modify a record that already exists in the database. It's used for things like profile updates, order status changes, marking messages as read, or editing product prices. Forgetting the WHERE condition in an UPDATE is risky—it can end up updating the entire table.
php
<?php
$id = 1;
$newMessage = "I am learning PHP with practical examples.";
$stmt = $conn->prepare("UPDATE contacts SET message = ? WHERE id = ?");
$stmt->bind_param("si", $newMessage, $id);
if ($stmt->execute()) {
echo "Message updated.";
} else {
echo "Update failed.";
}
$stmt->close();
?>You should see
Message updated.