错误的语法查询SQL

时间:2015-05-25 13:00:57

标签: php mysql sql

我需要选择具有特定名称的用户:

mysql_query('select * from user where screen_name='.$userName.'');

任何人都可以在我错的地方帮助我?

3 个答案:

答案 0 :(得分:0)

是错误的sql:

mysql_query('select * from user where screen_name="'.$userName.'"');

答案 1 :(得分:0)

mysql_query("select * from user where screen_name = '".$userName."';");

更好(在我看来)

$sql = "SELECT * FROM `user` WHERE `screen_name` = '".$userName."';";
mysql_query($sql);

更好 - 使用mysqli ....

答案 2 :(得分:-1)

mysql_query("select * from user where screen_name='$userName'");

尝试.....