• Resolved aaen

    (@aaen)


    Hi,

    I’m trying to develop my first WordPress plugin, but I can’t the the plugin to create a table when it is activated. The recipes_activate() function get called upon activation, but the table is not created.

    My code is as follows:

    $recipes_tbl_recipes_name	= $wpdb->prefix.'recipes_recipes';
    
    function recipes_activate() {
      global $wpdb;
    
      require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
    
      if($wpdb->get_var("show tables like '$recipes_tbl_recipes_name'") != $recipes_tbl_recipes_name) {
    
        $sql = "CREATE TABLE ".$recipes_tbl_recipes_name." (
    	  	      id BIGINT(20) NOT NULL AUTO_INCREMENT,
    	  	      name VARCHAR(100) NOT NULL
                );";
    
        dbDelta($sql);
      }
    }
    
    register_activation_hook( basename(__FILE__), 'recipes_activate' );

    Any hints?

    /Rasmus

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Table not created on activation’ is closed to new replies.