Support » Plugins and Hacks » Hacks » $wpdb->insert duplicate entries

  • caldar23


    I’m working on a script that creates a new entry every time a php function is called in order to track how many times an ad has been served.

    I’ve created my table using this code:

    $adserve_table = "CREATE TABLE
           $adserve_table_name (
    	meta_id mediumint(9) NOT NULL AUTO_INCREMENT UNIQUE,
    	ad_id mediumint(9),
    	meta_key varchar(255),
    	meta_value longtext
    	) CHARACTER SET $charset ;";

    and I’m inserting the entry using this code:

    			'ad_id' => $id,
    			'meta_key' => 'serve',
    			'meta_value' => $time

    I’m pretty good with PHP and WordPress, but MySQL is something that I’m just learning and I’m wondering if I’ve coded the insert wrong, or if I’m just bad at MySQL.

    I’m pretty sure it’s not going though this insert code, than some other insert code, cause when I change what gets inserted, the change gets inserted twice.

    I’m not sure if the code is being ran twice, I only see it once on the page. This is being displayed by using shortcode, has anyone had any issues with that?

    The only other thing that I can think of is that it might be a variable is that this is a local installation.

    I’d appreciate any help that I can get.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz


    You are saying this insert code is part of a shortcode handler? I’ve noticed several times that actions and filters often fire more often than one would expect. I’ve not observed this in shortcode handlers, but it’s not a big stretch of imagination to add it into the actions and filters with unanticipated events category.

    Sometimes I’ve been able to trace the cause, other times it’s remained a mystery. Until I have lot’s of spare time, it will have to be “just one of those things” for me.



    Thanks, I’ll look into the shortcode and check that out. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘$wpdb->insert duplicate entries’ is closed to new replies.