SureshKumar Vegesna SureshKumar Vegesna - 1 year ago 86
MySQL Question

login with username or email address in php

I am trying to create a login with username or email

My code is:


if($username && $password) {
$query="select * from user_db where username='$username' and password='$password'";
} else if ($email && $password) {
$query="select * from user_db where email='$email' and password='$password'";

Login with username is success but login with email is not working. Please help me!

Answer Source

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.

$query = "select * from  user_db where ( username='$login' OR email = '$login') and password='$password'"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download