tjhilder Posted May 3, 2006 Share Posted May 3, 2006 Hi,I created my own online users script but it seems to be duplicating entries and I'm not sure why, maybe someone has an idea by looking at my code?i've added comments at the end of the queries to show what they do (although you'll probably figure that out without the comments.)[code]$delete_lookup = "DELETE FROM " . $sql_usersonline . " WHERE (date <= '" . $delete_date . "')"; // delete any entries 5 or more minutes old.if (!$delete_lookup_result = mysql_query($delete_lookup)){ echo "<p>Error: nothing deleted because <b>" . mysql_error() . "</b> the query was: " . $delete_lookup;}if(isset($signedin)){ $user_lookup = "SELECT ip_address FROM " . $sql_usersonline . " WHERE ip_address='" . $_SERVER['REMOTE_ADDR'] . "'"; // check if user exists if ($user_lookup_result = mysql_query($user_lookup)) { if(mysql_num_rows($user_lookup_result) == '1') { $online_db_query = "UPDATE " . $sql_usersonline . " SET date='" . $online_date . "', name='" . $online_name . "', url='" . $online_url . "', member_id='" . $member_id . "', ip_address='" . $online_ip . "' WHERE ip_address='" . $online_ip . "'"; // if user exists, update it. $update_members_visit = "UPDATE members SET last_active='" . $date_var . "' WHERE member_id='" . $member_id . "'"; // updates member table to last visited if (!$visit_result = mysql_query ($update_members_visit)) { echo "<p>Member's last active date not updated<!-- because: <b>" . mysql_error() . "</b>.</p><p>The query was $update_members_visit -->.</p>"; } } else { $online_db_query = "INSERT INTO " . $sql_usersonline . " (`date`, `name`, `url`, `member_id`, `ip_address`) VALUE ('" . $online_date . "', '" . $online_name . "', '" . $online_url . "', '" . $member_id . "', '" . $online_ip . "')"; // if not exist, insert it. } if (!$online_result = mysql_query ($online_db_query)) { echo "<p>Online Users not updated<!-- because: <b>" . mysql_error() . "</b>.</p><p>The query was $online_db_query -->.</p>"; } } else { echo "<p>Error: <b>" . mysql_error() . "</b>.</p><p>The query was $user_lookup.</p>"; }}else{ $guest_lookup = "SELECT ip_address FROM " . $sql_usersonline . " WHERE ip_address='" . $_SERVER['REMOTE_ADDR'] . "'"; // no user, check if guest exists. if ($guest_lookup_result = mysql_query($guest_lookup)) { if(mysql_num_rows($guest_lookup_result) == '1') { $online_db_query = "UPDATE " . $sql_usersonline . " SET date='" . $online_date . "', name='" . $online_name . "', url='" . $online_url . "', member_id='', ip_address='" . $online_ip . "' WHERE ip_address='" . $online_ip . "'"; // if guest exists, update it. } else { $online_db_query = "INSERT INTO " . $sql_usersonline . " (`date`, `name`, `url`, `member_id`, `ip_address`) VALUE ('" . $online_date . "', '" . $online_name . "', '" . $online_url . "', '', '" . $online_ip . "')"; // if guest doesn't exist, insert it. } if (!$online_result = mysql_query ($online_db_query)) { echo "<p>Online Users, not updated<!-- because: <b>" . mysql_error() . "</b>.</p><p>The query was $online_db_query -->.</p>"; } } else { echo "<p><b>" . mysql_error() . "</b>.</p><p>The query was $guest_lookup.</p>"; }}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/8964-created-an-online-users-script/ Share on other sites More sharing options...
fenway Posted May 4, 2006 Share Posted May 4, 2006 Ugh.. don't post entire scripts. It sounds like you might be POSTing to this page multiple times. Your INSERT statement isn't in a loop, so that can't be it. Quote Link to comment https://forums.phpfreaks.com/topic/8964-created-an-online-users-script/#findComment-33189 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.