• Hi,

    I’m creating my first WordPress plugin and I’m already hitting a problem. I need to create a table when activating my plugin, but it doesn’t work. here’s my code:

    <?php
    /*
     * Plugin Name: plugin name
     * Description: bla bla bla
     * Version: 1.0
     * Author: Author
     */
    
    register_activation_hook(__FILE__, 'flashplayer_install');
    
    function flashplayer_install(){
    
        global $wpdb;
    
        $tbl_name = $wpdb->prefix.'flashplayer';
    
        if( $wpdb->get_var("show tables like '$tbl_name'") != $tbl_name ){
    
            $sql = "CREATE TABLE ".$tbl_name." (
                        id INT(10) NOT NULL AUTO INCREMENT,
                        title TINYTEXT NOT NULL,
                        filename VARCHAR(100) NOT NULL,
                        UNIQUE KEY id(id)
                    );";
            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
            dbDelta($sql);
    
        }
    
    }
    
    ?>

    What Am I doing wrong here?

Viewing 1 replies (of 1 total)
  • Sorry, you probably fixed this long time ago …

    I guess it’s the missing empty space after ‘prefix’. make it

    $tbl_name = $wpdb->prefix .’flashplayer’;

Viewing 1 replies (of 1 total)
  • The topic ‘my first wp plugin, create table doesn't work’ is closed to new replies.