Forum Moderators: coopster
if ($user_info = mysql_fetch_assoc($login_result)) {
foreach($user_info as $key => $val) {
$$key = stripslashes($val);
$_SESSION[$key] = $val;
}
}
however, if instead I use
if ($user_info = mysql_fetch_array($login_result)) {rest is the same}
it saves nothing to the session file and crashes when I call a session var "index does not exist". Sure enough if I print_r($_SESSION), I get nothing but an empty array.
I thought it might be because $$key doesn't give a proper name for the index when it is the numeric index, but when I do a print_r($_SESSION) before going to the next page, everything looks as it should
Array ( [0] => Baggins [last_name] => Baggins [1] => Bilbo [first_name] => Bilbo)
Why is that?
Tom
Perhaps you're being tripped up by the variable variable. The idea is not to assign $val to $key, but to assign $val to a variable whose name is equal to the value of $key.
so
$key = 'x';
$val = 321;
$$key = $val; // thus $x = 321
That should be simple enough and I don't think there's any problem there. Although variable variable can get turned around in my head.
Tom
if ($user_info = mysql_fetch_array($login_result, MYSQL_ASSOC)) {
I would think it would work like so, why do you want double vars set in the session?
It gives you the error on the next page? I would try something like
<?
session_start();
echo "<pre>";
print_r($_SESSION);
echo "</pre>";
?>
just to look at what exactly ends up in there on the next page.
OK, this is rather embarassing. Now I can't get it to NOT work. Last night I opened new browsers to make sure it wasn't a simple cache problem, always with the same result. Now that's all I can figure. I wish I had archived those files that weren't working.
Sorry for wasting everyone's time.
[sutpid stuff deleted]
Tom