1、错误查询语句:$sql='select * from sh_admin where username=$username and password=$password limit 1';2、正确查询语句:$sql = "select * from sh_admin where username = '{$username}' and password = '{$password}' limit 1";
When PHP operation MySQL database Why must use ' {$username} ' way to query, PHP syntax double quotes can parse variables Ah, why do I use the first kind of error?
Reply content:
1、错误查询语句:$sql='select * from sh_admin where username=$username and password=$password limit 1';2、正确查询语句:$sql = "select * from sh_admin where username = '{$username}' and password = '{$password}' limit 1";
When PHP operation MySQL database Why must use ' {$username} ' way to query, PHP syntax double quotes can parse variables Ah, why do I use the first kind of error?
1, variables $username and $password in single quotes is not resolved
2. The values after the Character field username and password need to be quoted.
$sql='select * from sh_admin where username="'.$username.'" and password="'.$password.'" limit 1';
Your first SQL uses single quotes, so it's a mistake.
is to use
$sql="select * from sh_admin where username=$username and password=$password limit 1";
There's no problem.
Agree upstairs, the string is to be quoted.
Debugging will $sql
output a bit, you can see at a glance!
The variable in the first single quotation mark is not parsed, and the string inside the SQL is to be caused.