I have got a basic login script at the moment.
When the user logs in 2 variables are defined:
$_SESSION['user_id'] = $user['user_id'];
$_SESSION['username'] = $user['username'];
the index.php file has this
session_start();
if(array_key_exists('user_id', $_SESSION) && array_key_exists('username', $_SESSION)):
That is all fine, however once the session is started I would like to add more values from a database so I have this code here:
$res = mysql_query($sql);
$_SESSION = mysql_fetch_assoc($res);
When I do this it overrides the $_SESSION[‘user_id’] and $_SESSION[‘username’].
I tried this:
$_SESSION .= mysql_fetch_assoc($res);
but it didn’t work.
Does anyone have any ideas?
Thanks
peter
That’s because you’re setting the value of the variable
$_SESSIONto the return value ofmysql_fetch_assoc($res);.What you want to do is something like
$_SESSION['query_result'] = mysql_fetch_assoc($res). If you just want to add a single column of your database result to the session you would do it like this: