Title: [Plugin: WP-UserOnline] WordPress database error Duplicate entry errors
Last modified: August 20, 2016

---

# [Plugin: WP-UserOnline] WordPress database error Duplicate entry errors

 *  [kuprosa](https://wordpress.org/support/users/metal450/)
 * (@metal450)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-wp-useronline-wordpress-database-error-duplicate-entry-errors-1/)
 * This plugin seems to be generating a large number of database errors (in error_log):
 * WordPress database error Duplicate entry ‘2010-10-06 06:35:31-xxx.xxx.xxx.xxx-
   Mozilla/4.0 (compatible;)’ for key ‘useronline_id’ for query INSERT INTO wp_useronline(
   user_type,user_id,user_name,user_ip,user_agent,page_title,page_url,referral) 
   VALUES (‘guest’,’0′,’Guest’,’xxx.xxx.xxx.xxx’,’Mozilla/4.0 (compatible;)’,’xxxxxx’,’/
   a-night-in-a-slovenian-prison’,”) made by require, require_once, include, get_header,
   locate_template, load_template, require_once, wp_head, do_action, call_user_func_array,
   UserOnline_Core->record
 * They don’t occur all the time, but they are fairly consistent – i.e. maybe a 
   few every day.
 * [http://wordpress.org/extend/plugins/wp-useronline/](http://wordpress.org/extend/plugins/wp-useronline/)

Viewing 15 replies - 1 through 15 (of 26 total)

1 [2](https://wordpress.org/support/topic/plugin-wp-useronline-wordpress-database-error-duplicate-entry-errors-1/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/plugin-wp-useronline-wordpress-database-error-duplicate-entry-errors-1/page/2/?output_format=md)

 *  Thread Starter [kuprosa](https://wordpress.org/support/users/metal450/)
 * (@metal450)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-wp-useronline-wordpress-database-error-duplicate-entry-errors-1/#post-2479551)
 * It seems as though this problem has existed for more than four and a half years:
 * [http://wordpress.org/support/topic/plugin-wp-useronline-plugin-28-wp301-broken](http://wordpress.org/support/topic/plugin-wp-useronline-plugin-28-wp301-broken)
 * And was reported a year ago:
 * [http://wordpress.org/support/topic/plugin-wp-useronline-wp-useronline-developing-error-messages](http://wordpress.org/support/topic/plugin-wp-useronline-wp-useronline-developing-error-messages)
 * By a few different users:
 * [http://wordpress.org/support/topic/plugin-wp-useronline-plugin-28-wp301-broken](http://wordpress.org/support/topic/plugin-wp-useronline-plugin-28-wp301-broken)
 * …Would be very nice to get this fixed up, as I find myself deleting error_logs
   virtually every time I ftp into my server 😛
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-wp-useronline-wordpress-database-error-duplicate-entry-errors-1/#post-2479552)
 * I can’t replicate the issue, so patches welcome.
 *  Thread Starter [kuprosa](https://wordpress.org/support/users/metal450/)
 * (@metal450)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-wp-useronline-wordpress-database-error-duplicate-entry-errors-1/#post-2479553)
 * Any information I could provide from my setup that might help? I did delve into
   the code a bit (obviously it’s coming from core.php, line 155 in v1.81), but 
   was not able to figure out much…
 *  Thread Starter [kuprosa](https://wordpress.org/support/users/metal450/)
 * (@metal450)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-wp-useronline-wordpress-database-error-duplicate-entry-errors-1/#post-2479554)
 * Actually, perhaps this is overly obvious, but is that “Purge table” deletion 
   immediately before the insert clearing previous records for the same user, so
   the new record can be inserted? If so, wouldn’t the solution just be something
   like changing:
 *     ```
       OR timestamp < DATE_SUB(CURRENT_TIMESTAMP, INTERVAL %d SECOND)
       ```
   
 * to
 *     ```
       OR timestamp <= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL %d SECOND)
       ```
   
 * so that if there’s already a record of the current user at the SAME moment (or
   earlier) it’ll be deleted?
 *  Thread Starter [kuprosa](https://wordpress.org/support/users/metal450/)
 * (@metal450)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-wp-useronline-wordpress-database-error-duplicate-entry-errors-1/#post-2479555)
 * …No wait, that wouldn’t be it. But what about just adding a WHERE to the insertion,
   i.e. something like:
 *     ```
       INSERT INTO wp_useronline (blahblah) VALUES (blahblah) WHERE not exists (SELECT * from wp_useronline WHERE user_ip = %s AND timestamp = CURRENT_TIMESTAMP AND user_type = $user_type);
       ```
   
 * Seems like that should *always* prevent such a duplicate entry, should it not?
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/plugin-wp-useronline-wordpress-database-error-duplicate-entry-errors-1/#post-2479556)
 * Alternatively, ON DUPLICATE KEY UPDATE could be used:
 * [http://dev.mysql.com/doc/refman/5.1/en/insert-on-duplicate.html](http://dev.mysql.com/doc/refman/5.1/en/insert-on-duplicate.html)
 * If you manage to get a query that no longer produces errors, please let me know.
 *  Thread Starter [kuprosa](https://wordpress.org/support/users/metal450/)
 * (@metal450)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/plugin-wp-useronline-wordpress-database-error-duplicate-entry-errors-1/#post-2479557)
 * Honestly, I’ve never worked directly with the database and wouldn’t really be
   comfortable modifying the queries for fear of breaking the functionality or causing
   some otherwise unknown side-effect; I was just hoping to provide you some more
   insight on what maybe causing this (clearly long-standing) issue with your otherwise
   flawless (as I can tell) plugin 😛
 * I came by all those other error reports just while Googling for a hopeful solution;
   the WHERE idea came from the first FAQ here: [http://www.techonthenet.com/sql/insert.php](http://www.techonthenet.com/sql/insert.php)
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/plugin-wp-useronline-wordpress-database-error-duplicate-entry-errors-1/#post-2479568)
 * I think I may have found at least one cause of the problem:
 * [http://wordpress.org/support/topic/plugin-wp-useronline-wordpress-database-error-duplicate-entry-errors-1](http://wordpress.org/support/topic/plugin-wp-useronline-wordpress-database-error-duplicate-entry-errors-1)
 *  Thread Starter [kuprosa](https://wordpress.org/support/users/metal450/)
 * (@metal450)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/plugin-wp-useronline-wordpress-database-error-duplicate-entry-errors-1/#post-2479569)
 * Sorry? Was that meant to have a link to a different thread/post? 🙂
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/plugin-wp-useronline-wordpress-database-error-duplicate-entry-errors-1/#post-2479570)
 * Heh… yeah: [http://wordpress.org/support/topic/plugin-wp-useronline-ipv6-support](http://wordpress.org/support/topic/plugin-wp-useronline-ipv6-support)
 *  Thread Starter [kuprosa](https://wordpress.org/support/users/metal450/)
 * (@metal450)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/plugin-wp-useronline-wordpress-database-error-duplicate-entry-errors-1/#post-2479572)
 * Nice! Expanded it to 39, will let you know if I keep getting those duplicate 
   error logs 🙂
 *  Thread Starter [kuprosa](https://wordpress.org/support/users/metal450/)
 * (@metal450)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/plugin-wp-useronline-wordpress-database-error-duplicate-entry-errors-1/#post-2479593)
 * I’m still getting these errors. I believe it’s happening most often during moments
   of very high server load, so that likely has something to do with it. In any 
   case, if the insert query itself takes into consideration the possibility of 
   duplicates (as in yours and my proposed solutions above), it should eliminate
   the risk of this happening once and for all…
 *  [kamalh](https://wordpress.org/support/users/kamalh/)
 * (@kamalh)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/plugin-wp-useronline-wordpress-database-error-duplicate-entry-errors-1/#post-2479594)
 * It’s been there forever.. To resolve the problem simply use the Mingle Users 
   Online plugin or else the real-time beta feature on Google analytics..
 *  Thread Starter [kuprosa](https://wordpress.org/support/users/metal450/)
 * (@metal450)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/plugin-wp-useronline-wordpress-database-error-duplicate-entry-errors-1/#post-2479595)
 * Mingle Users Online is a branch of this plugin and uses the exact same insert
   query. I don’t see how the bug wouldn’t occur with that plugin but would with
   this.
 * Google Analytics wouldn’t able to lookup the actual WordPress user account, just
   tell you that “someone” is online.
 *  [kamalh](https://wordpress.org/support/users/kamalh/)
 * (@kamalh)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/plugin-wp-useronline-wordpress-database-error-duplicate-entry-errors-1/#post-2479596)
 * Right, Mingle and the original plugin are the same. But the fact is the original
   plugin is full of bugs whereas this is not.
 * Analytics will of course not tell you who is online but otherwise it’s a great
   resource to know how many people are online and who is reading what..

Viewing 15 replies - 1 through 15 (of 26 total)

1 [2](https://wordpress.org/support/topic/plugin-wp-useronline-wordpress-database-error-duplicate-entry-errors-1/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/plugin-wp-useronline-wordpress-database-error-duplicate-entry-errors-1/page/2/?output_format=md)

The topic ‘[Plugin: WP-UserOnline] WordPress database error Duplicate entry errors’
is closed to new replies.

 * ![](https://ps.w.org/wp-useronline/assets/icon.svg?rev=978026)
 * [WP-UserOnline](https://wordpress.org/plugins/wp-useronline/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-useronline/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-useronline/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-useronline/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-useronline/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-useronline/reviews/)

 * 26 replies
 * 3 participants
 * Last reply from: [kuprosa](https://wordpress.org/support/users/metal450/)
 * Last activity: [14 years, 2 months ago](https://wordpress.org/support/topic/plugin-wp-useronline-wordpress-database-error-duplicate-entry-errors-1/page/2/#post-2479607)
 * Status: not resolved