【发布时间】:2015-07-28 22:01:16
【问题描述】:
我创建了一个指向 php 脚本的小型 xhtml 表单。无论我在密码字段中插入什么,它们都不会匹配。
我已经做了什么:阅读 php 手册中关于比较运算符的内容,并确保我使用了正确的运算符;验证 if 语法以确保没有任何错误;确保我在比较两个正确的字符串,并且这些值来自表单。
我想知道您的建议,因为我没有得到任何信息。
提前致谢,
贝加007
这是我的一些代码示例
<form action= "handle_reg.php" method= "post">
<p>First Name: <input type= "text" name= "first_name" size= "20" /></p>
<p>Last Name: <input type= "text" name= "last_name" size= "20" /></p>
<p>Email address: <input type= "text" name= "email" size= "20" /></p>
<p>Password: <input type= "password" name= "password" size= "20" /></p>
<p>Please confirm your password: <input type= "password" name= "confirm" size= "20" /></p>
<p>Favourite color: <input type= "text" name= "color" size= "5" /></p>
<!--Script continues but these are the lines which mattered-->
现在是 php 脚本
//Register Globals disabled
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$email=$_POST['email'];
$password=$_POST['password'];
$confirm=['confirm'];
$color=$_POST['color'];
$month=$_POST['month'];
$day=$_POST['day'];
$year=$_POST['year'];
//Script continues
//Checking password
if (empty ($password) ) {
print '<p>Please enter your password</p>';
} else {
print '<p>You have entered your password</p>';
}
//Checking if $confirm_password matches $password
if ($password != $confirm) { //ALWAYS returning true don't know why
print '<p>Your passwords doesn\'t match!</p>';
}
【问题讨论】:
-
$confirm=['confirm'];应该是$confirm=$_POST['confirm'];,对吧? -
@Don'tPanic 你应该发布作为答案,而不是评论。
-
@Gnarlywhale 我不想回答它,因为它应该被关闭。这只是一个错字。
-
如果你不这样做,仍然会有一些底部进纸器。
-
@Dagon 我现在是底部进纸器吗? ;)