我已经使用与我的 sql 数据库的会话创建了登录系统。当我输入正确的用户名和密码时,我可以登录。但是当我输入错误时,它没有显示Incorrect username or password
消息,它停留在 checklogin.php 页面(空白页面)。我该如何解决这个问题?这是 checklogin.php:
session_start();
$mypassword=$_POST['mypassword'];
$myusername=$_POST['myusername'];
$dbh = new PDO("mysql:host=$hostname;dbname=...", $username, $password);
$sql = "select * from user where username='$myusername' and password='$mypassword' ";
foreach ($dbh->query($sql) as $row){
if (isset($myusername) && isset($mypassword)) {
if (($row['username']==$myusername) && ($row['password']==$mypassword)) {
$_SESSION['login']='true';
echo "Login successfully";
echo"<a href='log_out.php'>Logout</a>";
}else{
echo "Incorrect username or password";
}
}
}