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

The problem is that I get as result nothing ! Please help cuz I can't find this error ! I have no idea what it can be !

  • First of all check this: http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php – Mark Jan 13 '15 at 19:14

2 Answers2

3

Your IF statement is wrong, you're setting instead of checking.

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

While you should do:

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

You forgot to put double = operator, instead of checking you were setting $user['username'] to false.

2

You did an assignment instead of a comparison so change this if statement:

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

to this:

if ($user['username'] == null)
                    //^^ See here 2x '='
Rizier123
  • 58,877
  • 16
  • 101
  • 156