-1
    <?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 !";
        }
    }
}
?>

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

4

2 回答 2

3

您的 IF 语句是错误的,您是在设置而不是检查。

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

虽然你应该这样做:

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

您忘了放 double = 运算符,而不是检查您是否将 $user['username'] 设置为 false。

于 2015-01-13T19:13:59.510 回答
3

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

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

对此:

if ($user['username'] == null)
                    //^^ See here 2x '='
于 2015-01-13T19:14:07.623 回答