我有一個代碼,我想在每個頁面上運行,但它似乎並不工作。如何將MySQL命令添加到每個頁面
<?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
但不acctually更新。
謝謝
db.php中有什麼? –
'var_dump($ id);'輸出是什麼? – Mike
這是我存儲用戶信息的數據,比如id變量。該命令應該可行,但事實並非如此。 –