php 检查两个密码是否匹配的注册表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3315803/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Registration Form Checking The Two Password Are Matching
提问by Maria T
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!
请帮我纠正我的编码。:-( 非常感谢!
回答by Matt Phillips
You can't reference both the variables inside the same $_POST
你不能在同一个 $_POST 中引用这两个变量
if ($_POST['pass']!= $_POST['pass2'])
{
echo("Oops! Password did not match! Try again. ");
}
回答by Maria T
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.
..谢谢你的帮助。
回答by cherouvim
if ($_POST['pass'] != $_POST['pass2'])
回答by Dhruv Tyagi
Inside the post you cannot reference both. So try this:
在帖子内,您不能同时引用两者。所以试试这个:
if(($_POST["pass"])!=($_POST["pass2"])){
echo"Oops! Password did not match! Try again.";
}
回答by Alexandru Dicu
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!');
}

