I have built a login system where I check if the user exists using either their username or their email address.
This is my code:
// DB Connection Included
$q = $dbcon->prepare("SELECT * FROM table WHERE (username=:e OR email=:e)");
$q->execute(array('e'=>$user));
But it doesn't work. It works perfectly if I change the query to:
$q = $dbcon->prepare("SELECT * FROM table WHERE username=:e)");
or
$q = $dbcon->prepare("SELECT * FROM table WHERE email=:e)");
I've used this code before and it has always worked perfectly, so I'm not sure why it doesn't work this time.
The actual error I get is a validation error in my code. I check to see if the user exists using the rowCount() function; using the desired query, rowCount() returns 0.
I have also tried:
$q = $dbcon->prepare("SET @user = :user SELECT * FROM table WHERE (username=@user OR email=@user)");
This was suggested on another post I found on Google, but this also did not work.
Does anyone have any suggestions?
Thanks in advance.