简体   繁体   中英

SQL query, getting error can't fix

I'm getting an error with this query:

"SELECT username 
and password 
FROM users 
WHERE username = $email , password = $password"

It's returning this error:

Error 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''users' WHERE username = $email , password = $password LIMIT 0, 30' at line 1

Put quotes around $email and $password. And use the AND in place of the comma in the WHERE clause. Something more like this:

$sql = "SELECT username, password 
FROM users 
WHERE username = '$email' AND password = '$password' LIMIT 1"
;

you are using , instead of and

 "SELECT username ,password 
    FROM users 
       WHERE username = $email and password = $password"

SELECT username,password FROM users WHERE username=$email AND password=$password

Use this:

"SELECT username, password 
FROM users 
WHERE username = '$email' AND password = '$password'"

Column names must be separated by comma, and string values between quotes.

Quote text parameters.

Use prepared statements if possible. These are much more advisable in order to avoid injection problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM