I am trying to create a login with username or email
My code is:
$username=$_REQUEST['login'];
$email=$_REQUEST['login'];
$password=$_REQUEST['password'];
if($username && $password) {
$query="select * from user_db where username='$username'";
} else if ($email && $password) {
$query="select * from user_db where email='$email'";
}
Login with username is success but login with email is not working.
The login parameter is the same for both email and username. Not exactly incorrect if you have a single login box that accepts either.
You could put the condition in the query itself if you’re not sure if it’s an email or username.
A PDO-like solution is much more preferred nowadays as the above is subject to SQL injection. The logic stays the same, but you’d have it look something like this: