i am begineer in wordpress , i want to create table when we activate a plugin .' i have written a code for the same but it is not working . can any one find out what is wrong with this code . so that it will create table successfully
<?php
/*
Plugin Name: dbtable
*/
$tbl = $wpdb->prefix . 'member';
function myreg_func(){
global $wpdb;
global $tbl;
$sql="CREATE TABLE IF NOT EXISTS $tbl (id int not null AUTO_INCREMENT,
em varchar(255) NOT NULL,
mob BIGING NOT NULL ,
nm varchar (225) NOT NULL ,
PRIMARY KEY(id))";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
}
register_activation_hook(__FILE__,'myreg_func');
?>
<?php
/*
Plugin Name: check
*/
function plugin_name_activation() {
require_once( ABSPATH . '/wp-admin/includes/upgrade.php' );
global $wpdb;
$db_table_name = $wpdb->prefix . 'member';
$sql = "CREATE TABLE " . $db_table_name . " (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`em` varchar(100) NOT NULL ,
`mob` int(20) NOT NULL,
`nm` varchar (225) NOT NULL ,
PRIMARY KEY (`id`)
) ;";
dbDelta( $sql );
}
register_activation_hook(__FILE__, 'plugin_name_activation');
?>
</div>