我正在使用此代码登录用户,并且我想更新MySQL数据库中已登录的列的值为yes。我在发送标题之前尝试更新它,但没有更新。我应该在哪里放置代码来更新列?当用户登录时在mysql数据库中更新列
if (isset($_POST['login']))
{
$username = trim(mysqli_real_escape_string($con, $_POST['username']));
$password = trim(mysqli_real_escape_string($con, $_POST['password']));
$md5password = md5($password);
// check user and password match to the database
$query = mysqli_query($con, "SELECT * FROM `user` WHERE username='$username' AND password='$md5password'");
// check how much rows return
if (mysqli_num_rows($query) == 1)
{
// login the user
// get the id of the user
$fetch = mysqli_fetch_assoc($query);
// start the session and store user id in the session
session_start();
$_SESSION['id'] = $fetch['id'];
$_SESSION['username'] = $fetch['username'];
$query = mysqli_query($con,"UPDATE user SET loggedin = 'yes' WHERE userid = 1;");
header("Location: message.php");
}
else
{
// show error message
echo "<div class='alert alert-danger'>Invalid username Or password.</div>";
}
}
不要紧,你把这样的命令。它必须被执行,就是这样。 – arkascha
也许问题是在这个代码的任何地方都没有'UPDATE'操作... – David
UPDATE'user' SET'loggedinin'='yes'WHERE'user'.'id' = 1;即时通讯使用这个,但它不会更新 –