jeudi 2 novembre 2017

How to show one echo out of two from my if statement (PHP)

Dear Stackoverflowers,

I'm having a school project and I'm making a login system where you can login with email or username. But I'm having a problem with showing the correct echo that the email or username is incorrect.

Here's my code:

if(strpos($emailOrUsername, "@")){
    $query = $dbh->prepare('SELECT * FROM register WHERE email = ?');
    $query->execute(array($emailOrUsername));
}

        if($query->rowCount() == 0){
                echo('Email is incorrect');

             }


if($emailOrUsername){
    $query2 = $dbh->prepare('SELECT * FROM register WHERE username = ?');
    $query2->execute(array($emailOrUsername));
}
        if($query2->rowCount() == 0){
                echo('Gebruikersnaam bestaat niet');

             }

Now I want to show only one echo. Because if you fill in the wrong email and username it's gonna show both echo's and I want it to show only one.

I hope one of you can help me as soon as possible.

Kind regards,

Stefan

Aucun commentaire:

Enregistrer un commentaire