Wordpress insert query adding three records one time

时间:2016-08-31 17:11:46

标签: php mysql wordpress

I am working on wordpress and facing a strange error . I am trying to insert data into table with $wptb->insert But it adds three records every-time . I have checked this Wordpress insert query runs 3 times But this doesn't help me.Here is my code

adding a blank page

add_submenu_page('', 'Duplicate', 'Duplicate', 'manage_options', 'lead-clone', 'clone_lead' );

function clone_lead

function clone_lead()
{
    global $wpdb;
    $table_name = $wpdb->prefix . "leads";
    $mycheckdata=array(
                    'author'=>'1',
                    'lead_submits_counts'=>'0',
                    'templateid'=>'12423432',
                    'template_title'=>'sdgfsg adas asdfsd',
                    'showtext'=>'asdgsfg',
                    'fieldtype'=>'gfsdgd',
                    'guid'=>'asdgfg',
                    'wsdl'=>'ASFasdfsdgfg'
                );
        $create=$wpdb->insert($table_name, $mycheckdata);
        die;
}

Please tell me where i am wrong . Thanks

1 个答案:

答案 0 :(得分:0)

Try this

function clone_lead()
{
global $wpdb;
$table_name = $wpdb->prefix . "leads";
$mycheckdata=array(
                'author'=>'1',
                'lead_submits_counts'=>'0',
                'templateid'=>'12423432',
                'template_title'=>'sdgfsg adas asdfsd',
                'showtext'=>'asdgsfg',
                'fieldtype'=>'gfsdgd',
                'guid'=>'asdgfg',
                'wsdl'=>'ASFasdfsdgfg'
            );
    $create=$wpdb->insert($table_name, $mycheckdata);
    //or you can use
    $wpdb->replace($table_name, $mycheckdata);
    if($wpdb->insert_id!="")
    return true;
    die;
}