0

Here's my code. Please help

function lapizzeria_database() {
   global $wpdb;

   global $lapizzeria_db_version;
   $lapizzeria_db_version = "1.0";

   $table = $wpdb->prefix . 'reservation';

   $charset_collate = $wpdb->get_charset_collate();

   //SQL Statement

   $sql = "CREATE TABLE $table (
        id mediumint(9) NOT NULL AUTO_INCREMENT,
        name varchar(50) NOT NULL,
        date datetime NOT NULL,
        email varchar(50) DEFAULT '' NOT NULL,
        phone varchar(10) NOT NULL
        message longtext NOT NULL,
        PRIMARY KEY (id)
   ) $charset_collate; ";

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

add_action('after_setup_theme', 'lapizzeria_database');
0

You are missing comma end of phone varchar(10) NOT NULL line, add comma end of line after that table will be created. I have tested https://prnt.sc/qgqmog

function lapizzeria_database() {
   global $wpdb;

   global $lapizzeria_db_version;
   $lapizzeria_db_version = "1.0";

   $table = $wpdb->prefix . 'reservation';

   $charset_collate = $wpdb->get_charset_collate();

   //SQL Statement

   $sql = "CREATE TABLE $table (
        id mediumint(9) NOT NULL AUTO_INCREMENT,
        name varchar(50) NOT NULL,
        date datetime NOT NULL,
        email varchar(50) DEFAULT '' NOT NULL,
        phone varchar(10) NOT NULL,
        message longtext NOT NULL,
        PRIMARY KEY (id)
   ) $charset_collate; ";

   require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
   dbDelta($sql);
}
add_action('after_setup_theme', 'lapizzeria_database');
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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