PHP更新不起作用

时间:2015-05-03 17:43:24

标签: php mysql mysqli phpmyadmin

在我的MySQL数据库中,我有一个名为CHECK的列,其中我的值只有1或0,当一个用户登录我的网站时,此值为1,当他注销时,将其设为0.但是......我不知道为什么这段代码不想在我的专栏上加1,有什么想法?

或者,如果有人知道如何检查一个用户是否已经登录或者没有请告诉我:)

这是我的数据库表 enter image description here     

pygame

1 个答案:

答案 0 :(得分:0)

试试这个?

<?
if ($username && $password_sha1) {
    $query = mysqli_query ( $conn, "SELECT * FROM portofoliu_table WHERE `account`='$username'" );
    $numrows = mysqli_num_rows ( $query );

    $val = 1;

    if ($numrows > 0) {

        while ( $row = mysqli_fetch_assoc ( $query ) ) {
            $db_account = $row['account'];
            $db_password = $row['password'];
        }
        if ($username == $db_account && $password_sha1 == $db_password) {

            //----------------------------------------HERE--------------------------------------------------------
            mysqli_query ( $conn, "UPDATE portofoliu_table SET `check`='$val' WHERE `account`='$username'" );
            //----------------------------------------------------------------------------------------------------

            $_SESSION['account'] = $username;
            $_SESSION["logged"] = true;

            header ( "location: AboutMe.php" );
            exit ();
        } else {
            echo "<div id='err'>That password is incorrect.</div>";
        }
        $_SESSION["logged"] = false;
        exit ();
    } else {
        die ( "<div id='err'>That user does not exist.</div>" );
    }
} else {
    die ( "<div id='err'>Please enter a username and password</div>" );
}
?>