I’m using the following code to create the database table using plugin.
However, the table is neither getting created nor I’m getting any error message.
The code is as follows:
global $wpdb;
$table_name = "tbllb_club";
$sql = "create table $table_name (
club_id int(11) NOT NULL auto_increment,
project_name varchar(500) NOT NULL,
first_name varchar(100) NOT NULL,
school_status varchar(50) NOT NULL,
school_name varchar(200) NOT NULL,
school_city varchar(50) NOT NULL,
school_state varchar(50) NOT NULL,
year_in_school varchar(50) NOT NULL,
age int(2) NOT NULL,
email varchar(200) NOT NULL,
mobile varchar(15) NOT NULL,
chat_id varchar(50) NOT NULL,
facebook_page_link varchar(200) NOT NULL,
mailing_address_street varchar(50) NOT NULL,
mailing_address_city varchar(50) NOT NULL,
mailing_address_state varchar(50) NOT NULL,
mailing_address_zip char(6) NOT NULL,
social_networking varchar(50) NOT NULL,
organization_involvement varchar(2000) NOT NULL,
yesclub_heard varchar(50) NOT NULL,
volunteer_experience varchar(2000) NOT NULL,
volunteer_reason varchar(2000) NOT NULL,
skills varchar(2000) NOT NULL,
creative_ideas varchar(5000) NOT NULL,
other_information varchar(2000) NOT NULL,
face_photo_url varchar(200),
school_image_url varchar(200),
video_clip_url varchar(200),
PRIMARY KEY (club_id)
);";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
I have followed the rules as mentioned the WordPress Codex.
Please help!!
Thanks in advance.
The above code should be placed in a function and then hook that with plugin activation hook? Here’s sample structure of
plugin-name.php
file.Code Updated on – 2012-08-04
Reference –
install_my_plugin()
function to create table.