在php中查询错误

时间:2011-03-06 08:46:20

标签: php mysql sql phpmyadmin

它说我的语法有错误,我似乎无法找到错误。

$query_admin = 'SELECT * FROM `user_accounts` WHERE `id` =1 AND `name` LIKE ' . $login_user_name . ' AND `password` LIKE ' . $login_password . ';
    $query_user = 'SELECT * FROM `user_accounts` WHERE `name` LIKE ' . $login_user_name . ' AND `password` LIKE ' . $login_password . ';

3 个答案:

答案 0 :(得分:1)

phpMyAdmin与此有什么关系?

你不应该以{{1​​}}结束你的行。这就是给你语法错误的原因。

只需删除它们就可以了。

答案 1 :(得分:1)

尝试这个我认为你忘了把'放在查询字符串的末尾:

$query_admin = "SELECT * FROM `user_accounts` WHERE `id` =1 AND `name` LIKE '$login_user_name' AND `password` LIKE ' $login_password'";
$query_user = "SELECT * FROM `user_accounts` WHERE `name` LIKE '$login_user_name ' AND `password` LIKE '$login_password' ";

或者这个:

$query_admin = "SELECT * FROM `user_accounts` WHERE `id` =1 AND `name` LIKE {$login_user_name} AND `password` LIKE {$login_password}";
$query_user = "SELECT * FROM `user_accounts` WHERE `name` LIKE {$login_user_name} AND `password` LIKE {$login_password}";

答案 2 :(得分:0)

我没有测试它。似乎是你最后有一个'到很多人。

'SELECT * FROM `user_accounts` WHERE `id` =1 AND `name` LIKE ' . $login_user_name . ' AND       `password` LIKE ' . $login_password ;