Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Guest
Mar 04, 2011 Mar 04, 2011

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.

TOPICS
Server side applications
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Mar 04, 2011 Mar 04, 2011

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

...
Translate
Guide ,
Mar 04, 2011 Mar 04, 2011

Please post the query code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 04, 2011 Mar 04, 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);
?>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 04, 2011 Mar 04, 2011

Well, the problem seems to be that the $_SESSION['MM_Username']) - value, which gets set in the LogIn page and will be carried over to other pages, can´t be used as filter criteria on other pages, because the username is now different -- and that´s why logging out and in again will solve this issue, because it´s only the LogIn page which is capable to assign a new value to this Session variable.

A more flexible way to grab the current user data via a Recordsert would be to check against a database record´s Primary Key instead, because this value will remain unchanged. Fortunately it´s possible to utilize another (barely documented) Session Variable named "MM_user_id", which can also be set in the LogIn page, although this will require some minor modification of the default PHP code.

Feel like doing this ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 04, 2011 Mar 04, 2011

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 04, 2011 Mar 04, 2011

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 04, 2011 Mar 04, 2011

Beautiful! Works perfect! Took me 5 min. I actually figured this is what I had to do, just didn't know the code to incorporate it. Thank you.

There are two other problems that arised from this...

1. I have a Welcome back (echo MM_Username). This is not updating after the user updates thier username. What should I put here now?

2. I currently have a Log In User behavior on my login page, after I updated the code on the login page manually it added another Log In User behavior and popped up this warning: (The Server Behavior panel cannot determine whether "Log In User" or "Log In User" is applied to your page. Please select Edit Server Behaviors and change one of the two behaviors to ensure that each is uniquely identifiable). I get what it's saying, but I only need one behavior for this page of course. Got any tips for this situation?

Thank you for your time.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 05, 2011 Mar 05, 2011

I have a Welcome back (echo MM_Username). This is not updating after the user updates thier username. What should I put here now?

As mentioned in my previous post, define a new Recordset which checks against the Session Variable MM_user_id, and insert the Dynamic Value "username" from the Bindings panel.

I currently have a Log In User behavior on my login page, after I updated the code on the login page manually it added another Log In User behavior and popped up this warning: (The Server Behavior panel cannot determine whether "Log In User" or "Log In User" is applied to your page. Please select Edit Server Behaviors and change one of the two behaviors to ensure that each is uniquely identifiable). I get what it's saying, but I only need one behavior for this page of course. Got any tips for this situation?

Mea Culpa ! I should have mentioned that Dreamweaver´s Server Behaviors tend to trips over manually modified behavior code and behave erratically. In this case we´re in luck, because Dreamweaver (just tested this with CS5) will fortunately not add any additional code or attempt to modify the existing one -- all what happens is, that you´ll get another dummy "Log In User" entry in the Server Behaviors panel, what doesn´t have any practical consequences. In other words: ignore this 😉

However in other cases (although this never happened to me) it´s in theory possible that Dreamweaver will attempt to modify the customized code, and for staying on the safe side it´s probably better to

a) modify code only on pages which are "ready for production", and/or

b) backup a customized file just in case

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 05, 2011 Mar 05, 2011

Awesome! Thank you. I thought exactly what you said for both questions, just wanted to see what you had to say. Damn I didn't want to have a Recordset on every page, but good thing I did a main template. Cause I have the Welcome back (user) on every page on the header. Also, I knew it was a bug. I've encountered a bug in all Adobe programs over the years. Just how it is. I am upgrading when I can.

You have been very helpful. Thank you again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 05, 2011 Mar 05, 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 😉

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 05, 2011 Mar 05, 2011
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines