• Hello,

    I m writing a small plugin and I need to create tables and add some default data in them. Now I have successfully created the tables but after creating the tables I have a function that is supposed to add data to one of the tables, but it doesnt add the data. Everything looks in order to me but it just doesnt work. Please help. Here is the code that is supposed to add sample data (I will add the code which created the database too, maybe the is something conflicting that I havent thought of)

    global $rsgs_db_version;
    $rsgs_db_version = "1.0";
    
    function rsgs_install(){
    	global $wpdb;
    	global $jal_db_version;
    	$table_orders = $wpdb->prefix . "rsgs_orders";
    	$table_products = $wpdb->prefix . "rsgs_products";
    
    	$sql = "CREATE TABLE $table_orders (
    		id mediumint(9) NOT NULL AUTO_INCREMENT,
    		ign varchar(255) NOT NULL,
    		msn varchar(255) NOT NULL,
    		amount int(11) NOT NULL,
    		total_sum float NOT NULL,
    		time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
    		status tinyint(1) DEFAULT 0,
    		type varchar(4) DEFAULT '' NOT NULL,
    		UNIQUE  KEY id (id)
    	);
    	CREATE TABLE $table_products (
    	id tinyint(5) NOT NULL AUTO_INCREMENT,
    	price float NOT NULL,
    	stock int(9),
    	UNIQUE  KEY id (id)
    	);
    	";
    
    	require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    	dbDelta($sql);
    
    	add_option("rsgs_db_version", $rsgs_db_version);
    }
    
    function rsgs_install_data(){
    	global $wpdb;
    	$rows_affected = $wpdb->insert($table_name, array('ign'=>'test','msn'=>'test@test.com', 'amount'=>100, 'total_sum'=>43.2, 'time'=>current_time('mysql'), 'type'=>'sell') );
    }
    
    register_activation_hook(__FILE__,'rsgs_install');
    register_activation_hook(__FILE__,'rsgs_install_data');
  • The topic ‘$wpdb->insert / register_activation_hook problem’ is closed to new replies.