I'm using PDO in PHP to connect to MySQL. My project is a chat app
Everytime someone sends a new message, I insert the message into table chat_messages
, and I update a timestamp in table chat_users
to indicate that that was the last time the user was active.
$sql = "INSERT INTO chat_messages
(email_sender, message, sent)
VALUES ('" . $email . "', '" . $message . "', '" . time() . "')";
$query = $pdo->prepare($sql);
if ($query->execute()) {
$sql2 = "UPDATE chat_users SET last_active = UNIX_TIMESTAMP()
WHERE email = '$email'";
$pdo->prepare($sql2)->execute();
// to test my query syntax is correct:
echo $sql2;
}
The timestamp is not being updated in the database. When i copy paste the output of echo $sql2
into phpMyAdmin, the query works.
What am i doing wrong?
Thank you