1

I am allowing people to input either their username, account number or email address before typing their password, so i need to compare their input against 3 fields in my table but i am not getting any results.

i first tried this ...

$result = mysqli_query($con,"SELECT * FROM useraccounts WHERE username='$thisuser' or accnum='$thisuser' or email='$thisuser'");

then i read on here that brackets should be placed around OR statements, so tried this ...

$result = mysqli_query($con,"SELECT * FROM useraccounts WHERE (username='$thisuser' or accnum='$thisuser' or email='$thisuser')");

but neither work, can someone help please

just for comparison, this does work when i type in the username value ...

$result = mysqli_query($con,"SELECT * FROM useraccounts WHERE username='$thisuser'");
7
  • Please paste the rest the rest of the code. Does $thisuser contain the correct value? Are you sure it exists in the database? Commented Feb 27, 2014 at 12:07
  • Could you print $result ? Commented Feb 27, 2014 at 12:08
  • 1
    The brackets are not needed there (you use them to force operator precedence, which would be required if you needed to check for a match on any of those fields AND the password). But both those queries look fine from a syntax point of view. Commented Feb 27, 2014 at 12:09
  • 1
    @DanFromGermany i think you are try to say setup SQLfiddle right ? Commented Feb 27, 2014 at 12:14
  • 1
    you should start by quoting your values correctly into the query Commented Feb 27, 2014 at 12:28

4 Answers 4

1

What is the datatype of accnum? Are you sure it is varchar?

If accnum is of type numeric then try

$result = mysqli_query($con,"SELECT * FROM useraccounts WHERE (username='$thisuser' or accnum=$thisuser or email='$thisuser')");
Sign up to request clarification or add additional context in comments.

4 Comments

it is numeric, and i have tried your code but still no joy
Have you tried executing the same query on mysql? and if you have allready tried that can you share some more code here, and make sure that $thisuser is not empty
yeah $this user has a value, i mentioned this in my original post - however i have made my accnum into a CHAR and it all seems ok now
try printing your query in php like $qstr="SELECT * FROM useraccounts WHERE (username='$thisuser' or accnum=$thisuser or email='$thisuser')"; print $qstr; $res=mysqli_query($con,$qstr); This may give you a hint what is happening.
0

Seems no problem. Please check '$thisuser' has value. Try printing the sql statement. You may try running query directly on database.

Comments

0

I also think first check the value of $thisuser, and then try below query

$result = mysqli_query($con,"SELECT * FROM useraccounts WHERE (username='".$thisuser."' or accnum='".$thisuser."' or email='".$thisuser."')");

Comments

0

Rathere then using at server side if it done at client side in js file by checking it emailid or username oraccount number according to that u can pass value

1 Comment

how can it client check without first accessing the database to make a comparison ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.