I’m creating a login for a website using PHP but when I try to login I always get the same error “You forgot to enter your password.” An error I included if the user forgets to enter the password, however I have been entering a password. Any help would be greatly appreciated.
The PHP:
//check for a password and a match against the confirmed password:
if (empty($_POST['pass1']))
{
if($_POST['pass1'] != $_POST['pass2'])
{
$errors[] = 'Your passwords did not match.';
}
else
{
$p = trim($_POST['pass1']);
}
}
else
{
$errors[] = 'Your forgot to enter your password.';
}
if (empty($errors)) //if everything is okay
{
//register the user in the database
require_once
('../mysqli_connect.php'); //connect to the DB
The HTML form:
<p>Password: <input type="password" name="pass1" size="15" maxlength="20"/>*</p>
<p>Confirm Password: <input type="password" name="pass2" size="15" maxlength="20"/>*</p>
Thank in advance!
Your code says to send the error message if the password is NOT empty (
elsecase of empty). Either switch thethenandelseblocks around, or put a!beforeempty.