Skip to main content
March 4, 2011
Answered

Logged-in user info doesn't display after the user updates their info

  • March 4, 2011
  • 1 reply
  • 1651 views

I created 2 pages. Page 1 has a recordset that displays only the users username and password, I did a filter on this recordset as username = session var = MM_Username. when they click update, which is just a link to page 2, they go to page 2 which has a recordset that filters their user info the same way and allows them to update their username and password. I used an update behavior on this page as well. So, when the user updates their info it DOES change the database info and works great.

The problem: When the user goes back to page 1 to see their updated username and password that they just updated, it is BLANK. no info displays on screen, even when I refresh the page. it's if the MM_Username var is not refreshing while logged-in. Because when the user logs out and logs back in, it DOES display new username and password on page 1.

Now it DOES work when I take the filter off of page 1's recordset, but this won't do me any good b/c the user should of course only see their info.

I am running DW CS3, php, and mysql.

Please Help! thanks.

This topic has been closed for replies.
Correct answer Günter_Schenk

yeah let's do it! I know a little php and can handle it.


I know a little php and can handle it.

Great, because this will save you from my usual lengthy gibberish ;-)

I´m attaching a screenshot of the modified LogIn page PHP code, which has just three new lines to take heed of.

Line 1: add the primary key of your "users" table to the query

Line 2: add the mysql_fetch_row function whose resource is the existing $LoginRS variable

Line 3: add the Session Variable MM_user_id and assign the $row[0] variable (see line 2).

Well, that´s it, and on other pages you can define a query such as...

"SELECT username, password FROM users WHERE id" equals the Session Variable MM_user_id

1 reply

Günter_Schenk
Inspiring
March 4, 2011

Please post the query code.

March 4, 2011
PAGE 1

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", 
$theNotDefinedValue = "")
{
   $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : 
$theValue;

   $theValue = function_exists("mysql_real_escape_string") ? 
mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

   switch ($theType) {
     case "text":
       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
       break;
     case "long":
     case "int":
       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
       break;
     case "double":
       $theValue = ($theValue != "") ? "'" . doubleval($theValue) . 
"'" : "NULL";
       break;
     case "date":
       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
       break;
     case "defined":
       $theValue = ($theValue != "") ? $theDefinedValue : 
$theNotDefinedValue;
       break;
   }
   return $theValue;
}
}

$colname_rsUpdateUser = "-1";
if (isset($_SESSION['MM_Username'])) {
   $colname_rsUpdateUser = $_SESSION['MM_Username'];
}
mysql_select_db($database_kh_space, $kh_space);
$query_rsUpdateUser = sprintf("SELECT username, parentEmail FROM users 
WHERE username = %s", GetSQLValueString($colname_rsUpdateUser, "text"));
$rsUpdateUser = mysql_query($query_rsUpdateUser, $kh_space) or 
die(mysql_error());
$row_rsUpdateUser = mysql_fetch_assoc($rsUpdateUser);
$totalRows_rsUpdateUser = mysql_num_rows($rsUpdateUser);
?>

PAGE 2

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", 
$theNotDefinedValue = "")
{
   $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : 
$theValue;

   $theValue = function_exists("mysql_real_escape_string") ? 
mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

   switch ($theType) {
     case "text":
       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
       break;
     case "long":
     case "int":
       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
       break;
     case "double":
       $theValue = ($theValue != "") ? "'" . doubleval($theValue) . 
"'" : "NULL";
       break;
     case "date":
       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
       break;
     case "defined":
       $theValue = ($theValue != "") ? $theDefinedValue : 
$theNotDefinedValue;
       break;
   }
   return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
   $updateSQL = sprintf("UPDATE users SET username=%s, password=%s 
WHERE userId=%s",
                        GetSQLValueString($_POST['username'], "text"),
                        GetSQLValueString($_POST['password'], "text"),
                        GetSQLValueString($_POST['userId'], "int"));

   mysql_select_db($database_kh_space, $kh_space);
   $Result1 = mysql_query($updateSQL, $kh_space) or die(mysql_error());

   $updateGoTo = "confirmation.php";
   if (isset($_SERVER['QUERY_STRING'])) {
     $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
     $updateGoTo .= $_SERVER['QUERY_STRING'];
   }
   header(sprintf("Location: %s", $updateGoTo));
}

$colname_rsUpdateUser = "-1";
if (isset($_SESSION['MM_Username'])) {
   $colname_rsUpdateUser = $_SESSION['MM_Username'];
}
mysql_select_db($database_kh_space, $kh_space);
$query_rsUpdateUser = sprintf("SELECT userId, username, password, 
parentEmail FROM users WHERE username = %s", 
GetSQLValueString($colname_rsUpdateUser, "text"));
$rsUpdateUser = mysql_query($query_rsUpdateUser, $kh_space) or 
die(mysql_error());
$row_rsUpdateUser = mysql_fetch_assoc($rsUpdateUser);
$totalRows_rsUpdateUser = mysql_num_rows($rsUpdateUser);
?>
March 6, 2011

Well, now that you (and other interested readers) know how to add the MM_user_id Session Variable to the LogIn page, it can´t hurt to know how to get rid of it (more accurate: unset) when a visitor logs out.

The attached screenshot shows the slightly modified "Log Out User" server behavior code, and the procedure is identical to what the "Log Out User" behavior does to the Session Variables "MM_Username" and "MM_Usergroup":

1. removing the variable and unset its value (NULL)

2. unset the variable

Enough said ;-)


Good idea. Didn't think of that. Very simple to do too, just copy what's already there. Thanks.