WordPress.org

Ready to get started?Download WordPress

Forums

$wpdb->insert duplicate entries (3 posts)

  1. caldar23
    Member
    Posted 1 year ago #

    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:

    $wpdb->insert(
    	$adserve_table_name,
    		array(
    			'ad_id' => $id,
    			'meta_key' => 'serve',
    			'meta_value' => $time
    		),
    		array(
    			'%d',
    			'%s',
    			'%d'
    		)
    	);

    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.

  2. bcworkz
    Member
    Posted 1 year ago #

    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.

  3. caldar23
    Member
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic