-4

This query works

SELECT id, username, password 
        FROM users
       WHERE (email = ?)
        LIMIT 1"
$stmt->bind_param('s', $email);
        $stmt->execute();
        $stmt->store_result();

This does not

SELECT id, username, password 
        FROM users
       WHERE (email = ? || username = ?)
        LIMIT 1"

Need to log in using both email as well as username having trouble in login in using only email

1
  • 2
    Please, just read How to Ask before asking a question. And the to-much-code protection isn't just a way for you so you can add a lot of a's so your post got accepted Oct 11, 2018 at 10:24

2 Answers 2

1

USE OR instead of ||

SELECT id, username, password 
        FROM users
       WHERE (email = ? OR username = ?)
        LIMIT 1
0
0

When declaring parameters, you can list all the types and then variables following it, example below;

$sql = "SELECT id, username, password FROM users WHERE (email = ? OR username = ?) LIMIT 1"

$stmt->bind_param('ss', $email, $username);

Additionally, as Shahnawaz said, use OR instead of ||.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.