DW UserID Session from Login

I'm trying to set a new Session Variable from the DW login page (UserID).  I found other questions/answers on this topic but for some reason my code is not working.  The login is successful and I can echo 'MM_Username' so I know sessions are working.  I must be doing something wrong when setting the UserID session.  Thanks for your help.  Here is the code.

$LoginRS__query=sprintf("SELECT pk_UserID, username, pwd FROM tlb_users WHERE username=%s AND pwd=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
  $LoginRS = mysql_query($LoginRS__query, $gagedb) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
      $newSessionId = $row_LoginRS['pk_UserID'];
      if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;      
      $_SESSION['MM_UserID'] = $newSessionId;      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];      
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rock216Author Commented:
Found my mistake.  Update to code:


$newSessionId = $row_LoginRS['pk_UserID'];


$row = mysql_fetch_assoc($LoginRS);
$_SESSION['MM_UserID'] = $row['pk_UserID'];

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.