SQL查询中的变量被视为列

时间:2016-06-03 11:43:05

标签: php mysql

我使用XCRUD框架。

我有一个问题:

$xcrud->query('SELECT * FROM table2 WHERE category IN (SELECT category FROM table1 WHERE '.$login_session.' = username)');

我一直收到以下错误:

 Unknown column 'userx' in 'where clause'

Userx是变量的值。

我也试过

$xcrud->query('SELECT * FROM table2 WHERE category IN (SELECT category FROM table1 WHERE '$login_session' = username)');

$xcrud->query('SELECT * FROM table2 WHERE category IN (SELECT category FROM table1 WHERE $login_session = username)');

我无法让我的查询工作。该变量被视为一个列。

5 个答案:

答案 0 :(得分:1)

像这样更改查询

$xcrud->query('SELECT * FROM table2 WHERE category IN (SELECT category FROM table1 WHERE username ="'.$login_session.'" )');

答案 1 :(得分:0)

试试这个;)

$xcrud->query("SELECT * FROM table2 WHERE category IN (SELECT category FROM table1 WHERE '".$login_session."' = username)");

答案 2 :(得分:0)

您需要在MYSQL-Queries中转义字符串。

where columnName = 'value' 

答案 3 :(得分:0)

$xcrud->query("SELECT * FROM table2 WHERE category IN (SELECT category FROM table1 WHERE username = $login_session)");

答案 4 :(得分:0)

$ xcrud-> query(“SELECT * FROM table2 WHERE category IN(SELECT category FROM table1 WHERE userx = $ login_session)”);