Ask me: Why is there no error message after submitting the wrong password in my code?
Logically speaking, it should not prompt: Sorry, the username or password is wrong, login failed!
<?php
if(isset($_POST['submit'])){
if(isset($_POST['username']) && isset ($_POST['password']) && $_POST['username']==='sunshengli' && $_POST['password']==='123456') {
if(setcookie(' username',$_POST['username'],time() 3600)) {
header('Location:http://www.sifangku.com/');
} else {
echo 'Cookie setting failed';
}
}
} else {
echo 'Sorry, username or Incorrect password, login failed! ';
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>User login</title>
</head>
<body>
<form method="post" action="login.php" >
Name:<input type="text" name="username " />
Password:<input type="password" name="password" />
<input type="submit" name="submit" value=" Login" />
</form>
</body>
</html>
if(isset($_POST['submit'])){
......
} else {
echo 'Sorry, username Or the password is wrong and login failed! ';
}
Your else determines the situation when the $_POST['submit'] variable is not defined. . .
else {
echo 'Sorry, the username or password is wrong, login failed! ';
}
You are judging if (isset($_POST['submit'])), not whether the account password is correct, so it is not displayed