jeudi 31 mars 2016

If statements php

I have a form, which collects a load of user data, before submitting the information to my database, it should check to see if the username is already taken, and if the two passwords entered are the same.

If I remove the password if statement, usernameError gets set and displays correctly.

If I remove the username statement the passwordError gets set and displays correctly

I need it to check both of these statements THEN submit to the database if the username doesn't exist AND the two passwords are the same.

The reason I'm using usernameError in the final part is just because it'll display a result if it is successful, once I get it working, I will change that to run an sql query. as it is now, no matter that I enter into the form, nothing happens.

The usernameError variable is declared at the start and is blank, it's always printed out onto the page it works, I've tested it, it just assigns it a value and it prints the value.

 if ($userQuery->execute()) {

    while ($row = $userQuery->fetch()) {

        if ($userQuery->rowCount() > 0) {

            $usernameError = 'username is already taken!';

        } else if ($_POST['passwordOne'] != $_POST['passwordTwo']) {

            $passwordError = 'passwords do not match!';

        } else {

            $usernameError = 'user saved';

        }
    }
}

Aucun commentaire:

Enregistrer un commentaire