用户的上次登录未在数据库中更新

时间:2015-06-03 07:05:13

标签: php login

我在我的用户表中插入了一个last_login字段并将$ update查询放在我的doLogin.php中,但是当用户登录时它不会更新数据库中的时间戳。是否有任何我遗漏的内容?

        $update = "UPDATE `user` SET last_login = NOW() WHERE  id='user_id'";
        $row = mysqli_fetch_array($result);
        $_SESSION['user_id'] = $row['id'];
        $_SESSION['username'] = $row['user_name'];
        $_SESSION['email'] = $row['email_address'];
        $_SESSION['gender'] = $row['gender_id'];
        $_SESSION['role_id'] = $row['role_id'];
        $msg1 = $_SESSION['username'];
        $msg2 = "Gender: " . $_SESSION['gender'] . "<br/>";
        $msg3 = "Email: " . $_SESSION['email'] . "<br/>";
        $msg .= "You are logged in as " . $_SESSION['role_type'] . "<br/>";

1 个答案:

答案 0 :(得分:1)

请参阅查询旁边添加的mysqli_query($update);

         $update = "UPDATE `user` SET last_login = NOW() WHERE  id='user_id'";
        mysqli_query($update);
        $row = mysqli_fetch_array($result);
        $_SESSION['user_id'] = $row['id'];
        $_SESSION['username'] = $row['user_name'];
        $_SESSION['email'] = $row['email_address'];
        $_SESSION['gender'] = $row['gender_id'];
        $_SESSION['role_id'] = $row['role_id'];
        $msg1 = $_SESSION['username'];
        $msg2 = "Gender: " . $_SESSION['gender'] . "<br/>";
        $msg3 = "Email: " . $_SESSION['email'] . "<br/>";
        $msg .= "You are logged in as " . $_SESSION['role_type'] . "<br/>";