0

I am trying to make a PHP-program for users to create a new account. This snippet shows how I tried to check if the username is already in my Database. If not, it continues. If the name is already taken the second if-loop should show the informations to the user and the program stops saving it. My Problem is, that the program jumps always into the second if-loop, doesnt matter if the username is already taken or not. It nevers saves a new user into my database.

Thank for your help in advance!

if(!$error) {

    $statement = $db->prepare("SELECT * FROM zugangsdaten WHERE nutzerid = ?");
    $statement->bind_param("s", $nutzerid);
    $result = $statement->execute();
    $user = $statement->fetch();
    var_dump("USER:", $user);

    if($user !== false){
        echo 'Dieses Nutzer-ID ist bereits vergeben.<br>';
        echo 'Bitte andere Nutzer-ID wählen. <br>';     
        $error = true;  
    }
}
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Josh
  • 51
  • 9
  • 2
    Did you read up on how to use `fetch`? http://php.net/manual/en/mysqli-stmt.fetch.php You are missing `bind_result`. – IncredibleHat Feb 25 '18 at 15:56
  • @IncredibleHat Thanks! Now it is saving it. But if I try to use the same name again, it doesnt jump into the second if-loop. The $user boolean value is now false. Do you know why? – Josh Feb 25 '18 at 16:35

0 Answers0