[英]Validation of password and confirm password in PHP Error shows all the time
因此,我试图创建一个登录表单,现在我想验证密码和确认密码。 每当我提交注册按钮时,即使我输入了相同的密码,我使用的代码(也可以在下面找到)都向我显示“密码和确认密码不匹配”。 任何想法应该在我的代码中进行哪些更改以消除错误?
<?php
session_start();
include('includes/config.php');
include('includes/db.php');
function isUnique($email){
$query="select * from users where email ='$email'";
global $db;
$result = $db->query($query);
if($result->num_rows>0){
return false;
}
else return true;
}
if(isset($_POST['register'])) {
$_SESSION['name']=$_POST ['name'];
$_SESSION['email']=$_POST ['email'];
$_SESSION['password']=$_POST ['password'];
$_SESSION['confirm_password']=$_POST ['confirm_password'];
if(strlen($_POST['name'])<3){
header("Location:register.php?err=".urlencode ("The name must be at least 3 characters long"));
exit();
}
else if(strlen($_POST['password']) < 5 ){
header("Location:register.php?err=".urlencode ("The password should be at least 5 characters"));
exit();
}
else if(strlen($_POST['confirm_password']) < 5 ){
header("Location:register.php?err=".urlencode ("The Confirm password should be at least 5 characters"));
exit();
}
else if(!isUnique($_POST['email'])){
header("location:register.php?err=".urlencode ("Email is already in use. Please use another one"));
exit();
}
else if($_POST['[password'] != $_POST['confirm_password']) {
header("Location:register.php?err=".urlencode ("The password and confirm password do not match"));
exit();
}
}
?>
这是我放置条件的另一部分,应在何时显示错误消息。
`<form action="register.php" method="post" style="margin-top:35px;">
<h2> Register Here </h2>
<?php
if(isset ($_GET['err'])) { ?>
<div class="alert alert-danger"><?php echo $_GET['err']; ?></div>
<?php }
?>`
您只是有一点错字:
代替$_POST['[password']
使用$_POST['password']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.