So i am trying to create a Login form and now i am at the part when i want to validate the password and the confirm password. The code i used (you can find it below) shows me everytime i submit Register button the "the password and confirm password do not match" even thought i enter the same password. any idea what should be changed in my code to remove the error?
<?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();
}
}
?>
and here is the other part where i put the condition when the error msg should be displayed.
`<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 }
?>`
You just had a little typo:
Instead of $_POST['[password']
use $_POST['password']
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.