I created a login form in PHP and now I have a password, email and username stored in the database when I use this query in my database form works correctly
$query = "SELECT * FROM users WHERE email = '$email' AND password='$password' ";
But when I add username functionality too it does not work correctly this is my username code
$query = "SELECT * FROM users WHERE username='$email' or email = '$email' AND password='$password' ";
Basically what happens is this, when I add username functionality when I try to login with username and type any password it logs in but when I try with email and try any password it says invalid and it works only with correct password now I want it to work correctly with username too
this is my whole code
<?php
session_start();
if (!isset($_SESSION['is_login'])) {
# code...
if (isset($_POST['btn_login'])) {
$email = mysqli_real_escape_string($con,trim($_POST['email']));
$password = mysqli_real_escape_string($con,md5(trim($_POST['password'])));
$query = "SELECT * FROM users WHERE username='$email' or email = '$email' AND password='$password' ";
$fire = mysqli_query($con,$query);
if ($fire) {
if (mysqli_num_rows($fire) == 1) {
$_SESSION['is_login'] = 'true';
$_SESSION['email'] = $email;
header("Location: dashboard");
}else{
$errorfname= '<p style="color:#cc0000;">invalid username or password</p>';
}
}
}
}else{
header("Location: dashboard.php");
}
?>
WHERE (username='$email' or email = '$email') AND password...