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 ag开发者_开发百科ain. ");
}
please help me to correct my coding. :-( thanks so much!
You can't reference both the variables inside the same $_POST
if ($_POST['pass']!= $_POST['pass2'])
{
echo("Oops! Password did not match! Try again. ");
}
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.
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!');
}
if ($_POST['pass'] != $_POST['pass2'])
Inside the post you cannot reference both. So try this:
if(($_POST["pass"])!=($_POST["pass2"])){
echo"Oops! Password did not match! Try again.";
}
精彩评论