I have problem with my code i am creating a login system in PHP, the problem is when username and password matches its OK everything works as it should but in other case if username or password don't match it should display "Authentication Failed!" message, it also diplays this message. but problem is it also Follows another message :
"Notice: Undefined variable: dbusername in C:\xampp\htdocs\abc\index.php on line 25"
Connecting to db and selecting table:
$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!");`
Fetching data:
while($row = mysqli_fetch_array($result)) {
$dbusername = $row['username'];
$dbpassword = $row['password'];
}
comparing username password with database username/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!";
}