Plugin could not be activated because it triggered a fatal error: unexpected ‘require_once’

I’m trying to create a custom table in MySQL using a plugin. Here’s the code for the same:

<?php
/*
Plugin Name: Zenva User Table
Plugin URI: http://www.getevangelized.com
Description: A custom table for storing user data
Version: 1.0
Author: Manas Chaturvedi
Author URI: http:www.getevangelized.com
License: GPL2
*/

register_activation_hook(__FILE__, 'create_update_table');


function create_update_table()
{
    global $wpdb;
    $tablename = $wpdb->prefix."twitteruser";

    if($wpdb->get_var("SHOW TABLES LIKE '$tablename'") != $tablename)
    {
        $sql = "CREATE TABLE `$tablename`(
            `user_id` INT(20) NOT NULL AUTO_INCREMENT,
            `twitter_handle` VARCHAR(100) NOT NULL,
            `oauth_token` VARCHAR(200) NOT NULL,
            `oauth_token_secret` VARCHAR(200) NOT NULL,
            `created` DATETIME,
            PRIMARY KEY (user_id)
            );" 

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

?>

However, while activating the plugin from WordPress dashboard, I’m encountering the following error:

Read More
Parse error: syntax error, unexpected 'require_once' (T_REQUIRE_ONCE) in /opt/lampp/htdocs/wordpress/wp-content/plugins/user_table/user_table.php on line 31

What seems to be wrong here? I did check to verify that I do have an upgrade.php file installed inside my WordPress installation.

What seems to be wrong here?

Related posts

1 comment

  1. There’s a semicolon missing at the end of the the $sql = "…" block.

    $sql = "CREATE TABLE `$tablename`(
        `user_id` INT(20) NOT NULL AUTO_INCREMENT,
        `twitter_handle` VARCHAR(100) NOT NULL,
        `oauth_token` VARCHAR(200) NOT NULL,
        `oauth_token_secret` VARCHAR(200) NOT NULL,
        `created` DATETIME,
        PRIMARY KEY (user_id)
        );";  // <---- here
    

Comments are closed.