0

Hello Community,
I was just wondering why my password matching section ( } else if (!$password === $cPassword) { ) in the else if isn't working.
Whats happening is it is saying the passwords do match but they don't. I have tried many ways to fix it there is one way to possible fix it i could have it as a single if but i don't want alot of if statements.

The script i'm using is below.

if (isset($_POST['submit'])) {
    if (isset($_POST['iAgree'])) {
        if (isset($_POST['fullName']) && isset($_POST['username']) && isset($_POST['email']) && isset($_POST['sQuestion']) && isset($_POST['sAnswer']) && isset($_POST['password']) && isset($_POST['cPassword'])) {
            $fullName = $_POST['fullName'];
            $username = $_POST['username'];
            $email = $_POST['email'];
            $sQuestion = $_POST['sQuestion'];
            $sAnswer = $_POST['sAnswer'];
            $password = $_POST['password'];
            $cPassword = $_POST['cPassword'];

            if (strlen($username)<6) {
                echo "The username length <font color='red'>must</font> be more than 6 characters.";
            } else if (strlen($password)<6) {
                echo "The password length <font color='red'>must</font> be more than 6 characters.";
            } else if (preg_match("/[^a-zA-Z0-9\_\-]+/", $username)) {
                echo "You username cannot contain any special characters.";
            } else if (!$password === $cPassword) {
                echo "Your passwords don't match!";
            } else {
                echo "Done";
            }
        }
        else
            echo "Please fill in <b>all</b> the fields!";
    }
    else
        echo "You <font color='red'>must</font> agree to the terms!";
}

Please help...

3
Contributors
6
Replies
18
Views
4 Years
Discussion Span
Last Post by joshl_1995
0

lol i just tried that and it worked i came back here to mark it as solved, but thanks anyway.

0

Coding tip: never leave open elses.
Like if(true) { ...; } else ...;
Alway wrap both sides: if(true) { ...; } else { ...; }

You leave yourself open to hard to find bugs with this.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.