要做到这一点,你需要匹配的用户ID的活动如不这样做,你最终将每次更新用户记录。
试试这个:
if(!isset($_SESSION)){//check if we already have a session at the moment
session_start();
}
$user_id = $_SESSION['id'];//change to your session id key
$stmt = $db->prepare("UPDATE users SET DateLastVisit = ? WHERE id_user = ?");//change id_user to what you have in your database
/*always check whether the prepare() succeeded */
if ($stmt === false) {
trigger_error($db->error, E_USER_ERROR);
}
$stmt->bind_param('si', $Date, $user_id); // we bind the user_id as well
$stmt->execute(); //execute, returns true/false
$result = $stmt->get_result();
$stmt->close();