Log in with user or email in the same field

Asked

Viewed 398 times

0

Hello! I have a login code but, I can’t get the user to log in with your email or username using the same field! Below follows my code, the email on my base date is named "mail".

2 answers

0

If I understand your question and your code correctly, just put one OR:

$userq = mysql_query("SELECT username, password FROM users WHERE (username = '{HoloText($_POST['credentials_username'])}' OR mail='$email') AND password = '$pwd' LIMIT 1");

Tip: Sometimes use the javascript to make a validation of the fields becomes better and simpler.

  • Pq the limit 1? It is not enough to check whether or not there is?

  • @Davidsamm Was C&P of the AP code.

0

So that you can log in with username and email at the same time, you should add in your query an OR. Example

SELECT username, password FROM users 
WHERE (username = "usernameRecebido" OR email = "emailRecebido") 
AND password = "passwordRecebido"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.