1

I get this error:

Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number in

this is my code (this does not work):

"SELECT id, username, email, password FROM users WHERE (username = :usernameOrEmail OR email = :usernameOrEmail) AND password = :password"

but if I remove the the OR, then it works!

"SELECT id, username, email, password FROM users WHERE username = :usernameOrEmail AND password = :password"
packnob890
  • 139
  • 1
  • 8
  • 1
    your first query also looks fine. But try once `"SELECT id, username, email, password FROM users WHERE password = :password AND (username = :usernameOrEmail OR email = :usernameOrEmail)"` and let us know worked or not. May be you have some error in the next line when you are assigning the values to `:usernameOrEmail` and `:password` – Alive to die - Anant Nov 17 '16 at 05:14
  • You may have to bind `:usernameOrEmail` twice. Just because you use the same parameter does not mean you won't need 3 bindings. – Tim Biegeleisen Nov 17 '16 at 05:15
  • using prepare ? – safin chacko Nov 17 '16 at 05:16
  • You cannot use a named parameter marker of the same name twice in a prepared statement : – safin chacko Nov 17 '16 at 05:16

2 Answers2

-1

This is PHP version BUG
You tried update php version

-2

Try with the below query

SELECT 
    id, username, email, password 
FROM 
    users 
WHERE 
    :usernameOrEmail 
    IN (username,email) 
    AND password = :password

As you cannot use a named parameter marker more than one times in a query.

sunkuet02
  • 2,376
  • 1
  • 26
  • 33