3

I want to create a table into the database upon installing the plugin I've created.

In my main plugin file (index.php):

register_activation_hook(__FILE__, 'wnm_install');

global $wnm_db_version;
$wnm_db_version = "1.0";

function wnm_install(){
global $wpdb;
global $wnm_db_version;
$sql = "CREATE TABLE tbl_campaigns (
campaignID int(11) NOT NULL AUTO_INCREMENT,
campaign_name varchar(128) NOT NULL,
start_duration date NOT NULL,
end_duration date NOT NULL,
activity varchar(500) NOT NULL,
survey_settings varchar(50) NOT NULL,
limit varchar(50) NOT NULL,
goal varchar(100) DEFAULT NULL,
PRIMARY KEY (campaignID)
) ;";

require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
add_option("wnm_db_version", $wnm_db_version);
}

I just followed the instructions from this http://codex.wordpress.org/Creating_Tables_with_Plugins

But it doesn't work.

What seems to be the problem with this code?

9
  • 1
    Are you getting any error in the error_log? What happens if you execute the query directly in MySQL console? Commented Apr 23, 2012 at 5:18
  • there's no error man. it just doesnt work. Commented Apr 23, 2012 at 5:25
  • Why is there a semi-colon at the end of the query string?? Commented Apr 23, 2012 at 5:26
  • i guess that semi-colon is ok. why? Commented Apr 23, 2012 at 5:35
  • Semi-colons don't belong in query strings. at least i've never seen them there. Commented Apr 23, 2012 at 5:37

1 Answer 1

6
limit varchar(50) NOT NULL,

Limit is a keyword, change to something else like

`limit` varchar(50) NOT NULL,

Use back ticks around keywords

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.