Reputation: 3224
I'm creating a wordpress plugin for woocommerce and the table i've created is not being inserted into the database? I get the error The plugin generated 5090 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.
Here is the code:
register_activation_hook( __FILE__, 'pato_install' );
register_activation_hook( __FILE__, 'pato_install_data' );
function pato_install() {
global $wpdb;
$table_name = $wpdb->prefix . 'pato_shipping';
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
pato_shipping_data text NOT NULL,
);";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
}
function pato_install_data() {
global $wpdb;
$table_name = $wpdb->prefix . 'pato_shipping';
//shipping options flat rate charges
$option_array = array(
'plants_fast' => '45.5',
'plants_standard' => '0');
//shipping condition values
$condition_array = array(
'plant_quantity_m1_1' => '3',
'plant_quantity_m1_2' => '6',
'plant_quantity_m2_1' => '6',
'plant_quantity_m3_1' => '3');
//shipping item charges
$item_charge_array = array(
'plants_ml_1_charge' => '49.5',
'plants_m2_1_charge' => '69.5',
'plants_m3_1_charge' => '89.5');
$data_array = array_merge($option_array,$condition_array,$item_charge_array);
$data_array = serialize($data_array);
$wpdb->insert(
$table_name,
array('pato_shipping_data' => $data_array)
);
}
Where did i go wrong?
Upvotes: 0
Views: 868
Reputation: 6976
You have some errors in your create table query. Your auto increment column needs to be a key and you have an extra trailing comma after your second column. Try:
CREATE TABLE $table (
id mediumint(9) NOT NULL PRIMARY KEY AUTO_INCREMENT,
pato_shipping_data text NOT NULL
)
I usually try to run my queries directly before incorporating them into a plugin. It makes debugging a lot easier.
Upvotes: 1