更改数据库中的ENUM值

时间:2016-06-08 08:17:59

标签: php mysql

我正在尝试更改mySQL数据库中ENUM的值,这将有助于确定用户登录或注销网站的时间,以便向网站的所有用户显示。我设置了一个ENUM列,可能的值为0和1. 0正在注销,1正在登录。但它似乎没有改变任何东西。这是我的代码:

    //LOGIN
session_start();

$username = ($_POST['username']);
$password = ($_POST['password']);

$sql = "SELECT * FROM users WHERE username = '$username' LIMIT 1";
$query = mysqli_query($conn, $sql);
if ($query) {
    $row = mysqli_fetch_row($query);
    $userid = $row[0];
    $dbusername = $row[1];
    $dbpassword = $row[2];
    $email = $row[4];
    $status = $row[7];
    $permit = $row[6];
    $active = $row[5];
    $fname = $row[8];
    $lname = $row[9];
    $dob = $row[10];
    $signupdate = $row[3];
    $ipadd = $row[11];
    $loggedin = $row[12];
}

if ($username == $dbusername && $password == $dbpassword){
    $_SESSION['username'] = $username;
    $_SESSION['id'] = $userid;
    $_SESSION['email'] = $email;
    $_SESSION['status'] = $status;
    $_SESSION['permit'] = $permit;
    $_SESSION['email_activation'] = $active;
    $_SESSION['first_name'] = $fname;
    $_SESSION['last_name'] = $lname;
    $_SESSION['dob'] = $dob;
    $_SESSION['sign_up_date'] = $signupdate;
    $_SESSION['ipv4'] = $ipadd;
    $_SESSION['loggedin'] = $loggedin;

    $sql = "UPDATE username SET loggedin = '1'";
    header("Location: ../main.php");

2 个答案:

答案 0 :(得分:0)

将此更新查询替换为此

"UPDATE users SET loggedin = '1' where `id` = $userid "; 

答案 1 :(得分:0)

   //LOGIN
session_start();

$username = ($_POST['username']);
$password = ($_POST['password']);

$sql = "SELECT * FROM users WHERE username = '$username' LIMIT 1";
$query = mysqli_query($conn, $sql);
if ($query) {
    $row = mysqli_fetch_row($query);
    $userid = $row[0];
    $dbusername = $row[1];
    $dbpassword = $row[2];
    $email = $row[4];
    $status = $row[7];
    $permit = $row[6];
    $active = $row[5];
    $fname = $row[8];
    $lname = $row[9];
    $dob = $row[10];
    $signupdate = $row[3];
    $ipadd = $row[11];
    $loggedin = $row[12];
    $sql = "UPDATE users SET loggedin = '1' where id = '$userid'";
    mysqli_query($conn, $sql);

}

if ($username == $dbusername && $password == $dbpassword){
    $_SESSION['username'] = $username;
    $_SESSION['id'] = $userid;
    $_SESSION['email'] = $email;
    $_SESSION['status'] = $status;
    $_SESSION['permit'] = $permit;
    $_SESSION['email_activation'] = $active;
    $_SESSION['first_name'] = $fname;
    $_SESSION['last_name'] = $lname;
    $_SESSION['dob'] = $dob;
    $_SESSION['sign_up_date'] = $signupdate;
    $_SESSION['ipv4'] = $ipadd;
    $_SESSION['loggedin'] = $loggedin;

    header("Location: ../main.php");