Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am working on creating a table in the DB for a plugin but cannot figure out why the table is not being created.

Here's my code:

global $ds_swoons_db_version;
$ds_swoons_db_version = '1.0';

function ds_swoons_install(){
global $wpdb;

$table_name = $wpdb->prefix . "ds_entry_swoons";    

if( $wpdb->get_var("show tables like '$table_name'") != $table_name ):
    $sql = "CREATE TABLE IF NOT EXISTS " . $table_name . " (
            id mediumint(9) NOT NULL AUTO_INCREMENT,
            post_id int(9) NOT NULL,
            user_id (9) NOT NULL,
            swoon_status int(1),
            UNIQUE KEY id (id)
            );";
    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    //make the query
    dbDelta($sql);
    //add db verison number
    add_option('ds_swoons_db_version', $ds_swoons_db_version);
endif;

}//end ds_swoons_install

register_activation_hook( __FILE__, 'ds_swoons_install');

I tried to echo the error but get an unexpected output error - probably due to headers being sent already. This is all the code I have so far - just wanted to see if I could create the table before moving on to anything else.

Thanx in advance!

EDIT ----------------------------------------------------

I figured it out - I did not have the data type declaration for user_id so it never created the table. I changed it and it worked :)

share|improve this question
    
You should post your answer as an answer rather than in your question. It just helps the community read easier. –  Brian Fegter Oct 16 '11 at 3:36
    
Hi, thanks for the heads up. I answered the question for clarity. –  dkmojo Oct 16 '11 at 23:54

1 Answer 1

I figured it out - I did not have the data type declaration for user_id so it never created the table. I changed it and it worked :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.