I have a code I would like to run on every page, however it doesn't seem to work at all.
<?php
include 'db.php';
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "User";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE users SET login_time=NOW() WHERE id='$id'";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();
?>
$sql = "UPDATE users SET login-time='NOW()' WHERE id='$id'";
Record updated successfully
This will never work:
if ($conn->query($sql) === TRUE) {
query() calls either return a statement handle/object (success), or a boolean FALSE (failure). They will never return a boolean TRUE, meaning that this comparison can never ever succeed. You should never have gotten a "success" message, only the "failed" one.