如果条件是真的但仍然跳跃在其他地方

时间:2016-05-10 10:05:08

标签: php

我使用php和ajax创建了一个登录脚本。密码我回显值,作为回报我发现文本框值和数据库值相同,但仍然跳转到else语句。我无法弄清楚代码的问题或我做错了什么。可能是其中一个人可以看到我的代码中是否有任何错误

$username = $_POST['username'];
    $pass     = mysqli_real_escape_string($connection, $_POST['password']);
    $pass     = md5($pass);

    $check  = mysqli_query($connection, "SELECT * FROM users WHERE username = '$username'");
    $result = mysqli_num_rows($check);
    if($result == 1) {
        $data = mysqli_fetch_array($check);
        $password_check = $data[2]; 

        if($password_check == $pass) {
            $_SESSION['uid']  = $data[0];
            $_SESSION['name'] = $data[3];
            echo "Success";
        } else {
            echo "<div class='message'>Invalid Password</div>";
        }
    } else {
        echo "<div class='message'>Username/Password did not matched</div>";
    }

0 个答案:

没有答案