Unable to create new database table upon plugin activation using dbDelta
I'm trying to create a new database table when my plugin is activated using dbDelta() however, no new table seems to be creating. Since I'm new to WordPress development, please let me know where I'm going wrong.
?php
/*
Plugin Name: Xenon-Result
Plugin URI: https://developer.wordpress.org/plugins/the-basics/
Description: Basic WordPress Plugin Header Comment
Version: 1.0
Author: Himanshu Gupta
Author URI: https://developer.wordpress.org/
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
function installer(){
include('installer.php');
}
register_activation_hook( __file__, 'installer' ); //executes installer php when installing plugin to create new database
add_action('admin_menu','result_menu'); //wordpress admin menu creation
function result_menu()
{
add_menu_page('Result','Result','administrator','xenon-result');
add_submenu_page( 'xenon-result', 'Manage Marks', ' Manage Marks', 'administrator', 'Manage-Xenon-Marks', 'Xenon_Marks' );
}
function Xenon_Marks()
{
include('new/result-add-marks.php');
}
?
This is the installer.php file:
?php
global $wpdb;
$table_name = $wpdb-prefix . "xenonresult";
$charset_collate = $wpdb-get_charset_collate();
if(!isset($table_name)){
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT
student-id mediumint(9) NOT NULL,
student-name text NOT NULL,
marks-obtained int(9) NOT NULL,
result text NOT NULL,
PRIMARY KEY (id)
) $charset_collate;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
}
?