What I hope is a simple PHP question....

Want to chit chat about anything, do it here ... posting here won't increase your post count (or shouldn't!). Please do not post any "phpBB" specific topics here unless they do not fit into the category above. Do not post bug reports, feature or support requests!
Forum rules
Please do not post any "phpBB" specific topics here unless they do not fit into the category above.

Do not post bug reports, feature or support requests! No really... Do not post bug reports, feature or support requests! Doing so will make Bertie a very sad bear indeed. :(
Post Reply
arlingtonjb
Registered User
Posts: 3
Joined: Sat Nov 05, 2005 2:02 am

What I hope is a simple PHP question....

Post by arlingtonjb »

I am developing a logging feature so I can keep up with how many time people access a certain PHP page, and want to record the user ID. The page itself works fine, but I cannot for the life of me get the logging to work properly.

It uses two different SQL calls, one to create a new "session" record in a custom table, and another that increments a custom user record field and records the "last visit" time in the user record.

The queries are written correctly, I think, but I am having 2 problems.... 9as you can tell, I am somewhat new to PHP coding...)

The $user_id field is not available for some reason, and I can't figure out the proper time value to use in the UPDATE or INSERT queries...

The question is, what includes need to be added to make those values available, and what syntax am I missing to have them work properely ? I'm including the top parts of the code. The //'d lines are the ones I need to figure out.

Any suggestions would be greatly appreciated.
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

//
// Start session management
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
// End session management
//

// UPDATE USER TABLE WITH CHAT VISITS AND CURRENT TIME
// $sql = "UPDATE " . USERS_TABLE . "
// SET user_chat_visits = user_chat_visits + 1, SET user_chat_last = UNIX_TIMESTAMP()
// WHERE user_id = '$user_id'";
// if (!$db->sql_query($sql))
// {
// message_die(CRITICAL_ERROR, "Could not update user chat data", "", __LINE__, __FILE__, $sql);
// }

// Create a chat session
// $sql = "INSERT INTO " . CHAT_SESSIONS_TABLE . " (user_id, sess_time)
// VALUES ('$user_id', int($currenttime))";
// if (!$db->sql_query($sql))
// {
// message_die(CRITICAL_ERROR, "Could not update chat session data", "", __LINE__, __FILE__, $sql);
// }
Sphen
Registered User
Posts: 36
Joined: Wed May 19, 2004 5:28 pm
Location: Land of the Beaver
Contact:

Re: What I hope is a simple PHP question....

Post by Sphen »

Hi,

What it looks like to me is that you're using the wrong SQL command. Try playing around with the UPDATE command instead of the SET command. Otherwise, it looks pretty good.

Good Luck :D

Sphen
I think, therefore I am, I think...
I refuse to have a battle of wits with someone who is unarmed.
Site - Blog
markus_petrux
Registered User
Posts: 376
Joined: Fri Jun 18, 2004 10:58 pm
Location: Girona, Catalunya (Spain)
Contact:

Re: What I hope is a simple PHP question....

Post by markus_petrux »

The SET keyword is coded twice, the second one is not needed. I think.

Aside, instead of UNIX_TIMESTAMP() isn't it better to use the same method used by phpBB itself? ie. using the PHP function time()
Post Reply