Skip navigation
QuintanN
Currently Being Moderated

Dreamweaver's "Log In User" - Storing more stuff in $_Session[]

Apr 9, 2012 12:45 PM

Tags: ##php ##login ##session ##variables

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.

 
Replies
  • Currently Being Moderated
    Apr 9, 2012 1:42 PM   in reply to QuintanN

    >$_SESSION['user_id']=$getAuth['user_id'];

     

    As far as I know, a session array is a one dimensional array - you can't store multiple values under 'user_id'. I'm not sure why you would want to. Why do you want to store a list of all users in a session variable?

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points