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...

Try:

else if ($password !== $cPassword)

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

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.

What are you talking about?

} else echo '...'; should rather be } else { echo '...'; }.
^ this

Yer, i know.
Where are you getting that from?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.