This topic is locked

insert or update data for user table (session or logged user)

4/14/2008 5:23:50 PM
PHPRunner General questions
E
erago author

Trying to update or insert data into Table "users" Field "LAST_ACTIVITY"

to record the date and time of the users last login. In Events / Global Events / Login page / After successful login
entered custom code as follows :
$strUpdate=

"UPDATE users

SET LAST_ACTIVITY = now()";

db_exec($strUpdate,$conn);
It Updates the correct field in the correct table BUT for ALL THE USERS not just the one.

have tried many variations of global $conn; and local $conn; and countless variations on the $_SESSION, $_SESSION["UserID"] and $SESSION["<table name>_OwnerID"] variables. creates either and error message, or has no effect.
What is the Proper Syntax to limit the change to the current user, and where does it go.

or is there another place I should place the code? or some other way of doing it?
have been searching the forum, PHPRunner Manual and the MYSQL manual Can't seem to find this. or at least nothing that has fixed it.

J
Jane 4/15/2008

Hi,
try to use this code:

global $conn;

$strUpdate="UPDATE users SET LAST_ACTIVITY = now() where UserName='".$_SESSION["UserID"]."'";

db_exec($strUpdate,$conn);



where UserName is your actual field name where username is stored.

E
erago author 4/15/2008

Hi,

try to use this code:
where UserName is your actual field name where username is stored.


Yes thank you that Fixed it. it was the Username field, I had be trying it with UserID field, in the where condition.

R
ringlis1 4/26/2008

What would the proper syntax be to adjust for adjusted date and time. I use this:

date('Y-m-d H:i', strtotime("-9 hour")) which works for the default value in the script, however, what do I need to do to update the data time the user last logged in.
I tried replacing Now() with several different ways, but, they all returned an error.
Thanks

J
Jane 4/28/2008

Hi,
try to use this one:

global $conn;

$strUpdate="UPDATE users SET LAST_ACTIVITY = '".date('Y-m-d H:i', strtotime("-9 hour"))."' where UserName='".$_SESSION["UserID"]."'";

db_exec($strUpdate,$conn);