PHP Code:
<?
$currenttime=date("U");
$endtime=$currenttime-60;
$query55689="DELETE FROM members_online WHERE time < $endtime";
$result55689=mysql_query($query55689);
if ($userlevel) {
$query55699="SELECT user FROM members_online WHERE user='$cookieuname'";
$result55699=mysql_query($query55699);
$num55699=mysql_num_rows($result55699);
if ($num55699 == '0') {
$query55="INSERT INTO members_online (user, time) VALUES ('" . $cookieuname . "', '" . $currenttime . "')";
$result55=mysql_query($query55);
} else {
$query2888="UPDATE members_online SET time = '$currenttime' WHERE user ='$cookiename'";
$result2888=mysql_query($query2888);
}}
?>
I'm making a 'Who's Online' system.
Basically what this script does first of all is deletes anyone from the 'members_online' table who haven't moved for the past 60 seconds (yes I know its a short time, ignore it). After it's done that it goes onto the user in hand.
- It gets the username stored in the cookie and searches for it in the 'members_online' table.
- If there are no names like that in the table, it will create a new one with a new time
- If there is, it'll simply update their time.
However this does not seem to be working. I opened my page once and the info went into the database perfectly, however when I refreshed or browsed my site, I noticed my time was not updating. Why is this?
Extra Notes: Variables '$cookieuname' and '$userlevel' ARE declared earlier in my script (this is just a snippet). They are definitely declared (and used elsewhere).
EDIT: I've just echoed $num55699 and it works perfectly so I'm guessing that something is wrong with the update section of the script then. Any help appreciated!
|