我的代码有问题我在PHP中创建一个登录系统,问题是当用户名和密码匹配时,一切正常,但在其他情况下,如果用户名或密码不匹配则应显示“身份验证”失败!”消息,它也显示此消息。但问题是它还遵循另一条消息:
“注意:未定义的变量:dbusername in 第25行的C:\ xampp \ htdocs \ abc \ index.php“
连接到数据库并选择表:
$con = mysqli_connect($hostname,$dbuser,$dbpass,$dbname) or die ("Could not connect to Data base !");
$result = mysqli_query($con,"SELECT * FROM persons WHERE username = '$username' AND password = '$password'") or die ("Could not query!");`
获取数据:
while($row = mysqli_fetch_array($result)) {
$dbusername = $row['username'];
$dbpassword = $row['password'];
}
将用户名密码与数据库用户名/密码进行比较:
if ($dbusername == $username AND $dbpassword == $password) // Checking if username and password matches with database's data..
{
echo "<br>"."You are logged in";
}
else
{
echo "Authentication Failed!";
}