I have a problem as the title says. My plugin does not create a custom table when it's activated. My code is:
function bsp_create_update_table() { global $wpdb; //geting the acces to a wp tables $tablename=$wpdb->prefix . "students"; //the name of a table with it's prefix //checking if the table with the name we created a line above exists if($wpdb->get_var("SHOW TABLES LIKE '$tablename'") != $tablename) { //if it does not exists we create the table $sql="CREATE TABLE `$tablename`( `students_id` INT(11) NOT NULL AUTO_INCREMENT, `students_name` VARCHAR (50) NOT NULL, `students_lastname` VARCHAR (50) NOT NULL, `students_email` VARCHAR 850) NOT NULL, `students_course` VARCHAR (100) NOT NULL, `students_date` DATETIME, PRIMARY KEY (students_id) );"; //wordpress function for updating the table require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } } And I have a hook like this: register_activation_hook(__FILE__, 'bsp_create_update_table');
When plugin is activated there is no table created and I just don't know why. Any ideas?
register_activation_hook( ... )in your main plugin file? Or in aninclude'ed one?