0

我有一个 Session 在用户登录时为他们存储数据,但我只能打印数据。像这样...

echo print_r($_SESSION);

将返回...

数组([user_id] => 5 [access_level] => 4 [user_name] => user1 [division] => NEB [dept] => ALL)1

但是当我输入这样的代码时......

$sql = "SELECT * FROM table where division = '".$_SESSION['division']."' ORDER BY status";

并回应那句话,它看起来像这样......

SELECT * FROM table where division = '' ORDER BY status

除非我回显会话变量,否则会话数据会消失!

请指教。

4

2 回答 2

0

这样做可能会更好

$division = $_SESSION['division'];
$sql = "SELECT * FROM table where division = '$division' ORDER BY status";

令人惊讶,但它会起作用。

于 2013-07-20T00:14:19.360 回答
0
$sql = "SELECT * FROM `table` WHERE division = '{$_SESSION['division']}' ORDER BY status";
于 2013-07-20T00:06:48.287 回答