为什么这个PHP代码如果其他条件不起作用?

时间:2016-03-26 20:46:13

标签: php

if (!empty) {}部分之后检查IF ELSE声明。

<form action="first.php" method ="post">
 <input type="text" name="username" >Username</br>
 <input type="password" name="password" >Password</br>
 <input type="submit"  value="Submit"></br>
</form>

<?php
if (isset($_POST['username'] )&& isset($_POST['password'])) {
    if (!empty($user) && !empty($pass)) {
        $user = $_POST['username'];
        $pass = $_POST['password'];

        if ($user ==="habib"  && $pass === "1234") {
            echo $user;
            echo $pass;
        } else {
            echo "wrong password and username";
        }
    }
}
?>

1 个答案:

答案 0 :(得分:2)

您需要检查$_POST['username']$_POST['password']是否为空,而不是$user$pass