1

这就是我所拥有的,我该怎么办?我想在一个会话中存储两个变量,它们是用户名和头像。

if ($count == 1) 
{
$row = mysqli_fetch_array($result);
//while ($_SESSION['username'] = $row['username'])
$_SESSION['users'] = [''];
$_SESSION['users']['username'] = $row['username'];
$_SESSION['users']['avatar'] = $row['avatar'];

{
session_start();
4

2 回答 2

4

Is there a reason you can't use:

$_SESSION['username'] = $row['username'];
$_SESSION['avatar'] = $row['avatar'];
于 2012-05-24T23:59:05.130 回答
3

First: Use session_start(); of the top of your code.

Second: What you mean with this row? "$_SESSION['users'] = [''];" If you want to initialize it you should use:

$_SESSION['users'] = array();

In short your code should like:

session_start();
.
.
.
if ($count == 1) 
{
$row = mysqli_fetch_array($result);
$_SESSION['users'] = array();
$_SESSION['users']['username'] = $row['username'];
$_SESSION['users']['avatar'] = $row['avatar'];
...

I hope this helps.

于 2012-05-24T23:58:57.587 回答