Maria T
Maria T

Reputation: 333

Registration Form Checking The Two Password Are Matching

I want to make this registration script tell the user when the passwords they have entered are not matching.

and i use this code:

 if ($_POST['pass' != 'pass2'])
 {
  echo
   ("Oops! Password did not match! Try again. ");
 }

please help me to correct my coding. :-( thanks so much!

Upvotes: 3

Views: 41647

Answers (5)

Alexandru Dicu
Alexandru Dicu

Reputation: 1235

You should also check if the passwords were not left empty or if they are not just blank spaces. Otherwise, two uncompleted fields are valid.

if(trim($_POST['pass'])=='' || trim($_POST['pass2'])=='')
{
    echo('All fields are required!');
}
else if($_POST['pass'] != $_POST['pass2'])
{
    echo('Passwords do not match!');
}

Upvotes: 2

Dhruv Tyagi
Dhruv Tyagi

Reputation: 812

Inside the post you cannot reference both. So try this:

if(($_POST["pass"])!=($_POST["pass2"])){
    echo"Oops! Password did not match! Try again.";
}

Upvotes: 1

Maria T
Maria T

Reputation: 333

if ($_POST['pass']!= $_POST['pass2'])
 {
     echo("Oops! Password did not match! Try again. ");
 }

.. i will use this code. and it also works. :-)

.. thanks for helping.

Upvotes: 3

Matt Phillips
Matt Phillips

Reputation: 11529

You can't reference both the variables inside the same $_POST

if ($_POST['pass']!= $_POST['pass2'])
 {
     echo("Oops! Password did not match! Try again. ");
 }

Upvotes: 10

cherouvim
cherouvim

Reputation: 31918

if ($_POST['pass'] != $_POST['pass2'])

Upvotes: 1

Related Questions