Blackwolf
Blackwolf

Reputation: 105

MySQL using WHERE and OR

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'");

Upvotes: 1

Views: 109

Answers (4)

Kittu
Kittu

Reputation: 19

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

Upvotes: 0

Supriya Pansare
Supriya Pansare

Reputation: 559

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."')");

Upvotes: 0

AnonymousCoder
AnonymousCoder

Reputation: 592

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')");

Upvotes: 1

Andolasoft Inc
Andolasoft Inc

Reputation: 1296

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

Upvotes: 0

Related Questions