This one has been driving me nuts for days. All I am trying to do is store something in the session variable on log in so I can call it like "$_Session['user_id']" (the field's name is "user_id"). I got excited when I found this Adobe Cookbooks tutorial "Display user's name and other details after login (PHP)" but as soon as I tried adding the lines on my Log In page
foreach ($row_getAuth as $col => $val) {
$_SESSION[$col] = $val;
}
immediately after the "$totalRows_getAuth = mysql_num_rows($getAuth);" line, just as the tutorial said, I would be sent to the "Logged In" page, however anywhere I tried echoing "$_SESSION['MM_Username]", it would come up as blank. If I comment out the loop, it works. It would appear as if the session had not been started.
I then removed the loop and tried adding the logged-in user's row's "user_id" column to the $_SESSION array by going
$_SESSION['user_id'] = $row_getAuth['user_id']; //names match up with MySQL field
The session breaks again but works fine (minus being able to do what I want) if I comment it. Is there something I am missing here? I'm fairly new to PHP but thought I had a decent grasp on what was going on. These variables are so hard to keep track of!
Since it's probably a good idea to show my code in a little bit of context, it's basically Dreamweaver's pre-canned Log In User behavior
.....
mysql_select_db($database_tpsContent, $tpsContent);
$query_getAuth = "SELECT user_id, username, pass FROM users";
$getAuth = mysql_query($query_getAuth, $tpsContent) or die(mysql_error());
$row_getAuth = mysql_fetch_assoc($getAuth);
$totalRows_getAuth = mysql_num_rows($getAuth);
$_SESSION['user_id']=$getAuth['user_id'];
.....
I really appreciate the help! Thanks in advance.
North America
Europe, Middle East and Africa
Asia Pacific