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>
蔚蓝的夜2017-11-27 11:16:49
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. . .
小丘2017-11-27 10:11:44
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
ringa_lee2017-11-27 09:34:25
<?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:www.sifangku.com/'); } else { echo 'cookie设置失败';exit; } }//这里添加密码错误执行的地方,但是你没有任何操作,当然也就不提示了。 //你可以加个else{ echo "账号密码错误";} } else { echo '对不起,用户名或密码错误,登录失败!'; } ?>