0

我不确定我做错了什么,基本上当用户登录时,我试图更新用户数据库中的“lastlogin”字段。

$login = login($username, $password);
    if ($login === false) {
        $errors[] = 'That username/password combination is incorrect';
    } else {
        $_SESSION['user_id'] = $login;
        $sql = "UPDATE `users` (lastlogin) VALUES ('now()') WHERE `user_id` = $user_id";
        header('Location: index.php');
        exit();
    }
4

2 回答 2

1

不需要使用'onnow()函数,添加SET:

$sql = "UPDATE `users` SET lastlogin = now() WHERE `user_id` = $user_id";

您没有执行任何 mysql 函数、PDOmysqli或旧的/贬低的mysql_*

考虑添加:

$mysqli = new mysqli("example.com", "user", "password", "database");
$res = $mysqli->query("UPDATE `users` SET lastlogin = now() WHERE `user_id` = $user_id");
于 2013-07-17T08:12:44.920 回答
0

将查询更改为:

$sql = "UPDATE `users` set lastlogin  = now() WHERE `user_id` = $user_id";
mysql_query($sql);
于 2013-07-17T08:16:16.203 回答