I Tried to create table in database with the help of register_activation_hook() but its not working….
function my_plugin_activation(){
global $wpdb , $table_prefix;
$wp_emp = $table_prefix.'emp';
$q = "CREATE TABLE IF NOT EXISTS` $wp_emp` (`id` INT NOT NULL , `name` VARCHAR(50) NOT NULL ,
`Email` VARCHAR(100) NOT NULL , `status` VARCHAR NOT NULL ) ENGINE = InnoDB;";
$wpdb -> query($q);
}
2
Answers
You need to add
register_activation_hook
in your plugin file to run any script during the activation of your plugin and call thedbDelta
function to execute thesql
command and includewp-admin/includes/upgrade.php
. For example:First, your table name is too short, so not accepted, and you need some more things:
Tested and works.
Notes:
Email
column name should need to be in lowercase.Related: I'm getting "Bad request" using ajax in custom WordPress plugin