执行后Php为空结果

时间:2015-01-13 19:12:38

标签: php nothing

    <?php
require_once 'init.php';

if(isset($_POST['username'], $_POST['password'])) {

$extractInfoUser = $db->prepare("
    SELECT * FROM user
    WHERE username = :username
");

$extractInfoUser->execute([
    'username' => $_POST['username']
]);

$users = $extractInfoUser->rowCount() ? $extractInfoUser : [] ;

foreach ($users as $user) {
    if ($user['username'] = null) {
        die("There is no username like this !");
        } else {
            echo "You are not able to register under this username !";
        }
    }
}
?>

问题是我得到了结果没有! 请帮助因为我找不到这个错误!我不知道它是什么!

2 个答案:

答案 0 :(得分:3)

您的IF声明错误,您正在设置而不是检查。

if ($user['username'] = null) {

你应该这样做:

if ($user['username'] == null) {

您忘记使用double =运算符,而不是检查您是否将$ user [&#39; username&#39;]设置为false。

答案 1 :(得分:3)

您执行了分配而不是比较,因此更改此if语句:

if ($user['username'] = null)

到此:

if ($user['username'] == null)
                    //^^ See here 2x '='