Title: $wpdb | installing custom table plugin
Last modified: August 20, 2016

---

# $wpdb | installing custom table plugin

 *  [michover](https://wordpress.org/support/users/michover/)
 * (@michover)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/wpdb-installing-custom-table-plugin/)
 * Please help, I’m desperate (new at plugins and I’m struggling) Creating a simple
   plugin for a uni assignment which is due in a few days –
 * Plugin not working 8o( – just simply want to install a custom database using 
   $wpdb – currently have 2 files to just configure the custom table (I am very 
   new to plugins so it’s going to be a really silly error). Once this is installed,
   I can use a custom form so that users can submit details to the custom table (
   next stage)
 * Nothing happens when the plugin is activated – it activates with no errors but
   the DB does not configure in phpmyadmin >>
 * File 1 – traderegistrationform.php
    File 2 – utddb_install.php
 * FILE 1: TRADEREGISTRATIONFORM.PHP
    <?php
 * /*
    Plugin Name: Trade Registration Form */ register_activation_hook(utddb_install.
   php,’utddb_install’); register_activation_hook(utddb_install.php,’utddb_install’);
 * ?>
 * FILE 2: UTDDB_INSTALL.PHP
 * <?php
 * /*
 * */
 * global $utddb_version;
    $utddb_version = “1.0”;
 * function utddb_install () {
    global $wpdb; global $utddb_version;
 * $tablename = $wpdb->prefix . “user_trade_details”;
 * $sql = “CREATE TABLE ‘$tablename’ (
    ‘company_id’ bigint(20) NOT NULL AUTO_INCREMENT,‘
   user_id’, bigin(20) ‘firstname’ varchar(60) NOT NULL, ‘lastname’ varchar(60) 
   NOT NULL, ‘contactno’ bigint(15) NOT NULL, ‘company_name’ varchar(100) NOT NULL,‘
   customer_type’ char(1) NOT NULL, ‘address_1’ text, ‘address_2’ text, ‘town’ text,‘
   county’ text, ‘post_code’ text, ‘registration_date’ datetime, ‘company_no’ bigin(
   20) );”;
 *  require_once(ABSPATH . ‘wp-admin/includes/upgrade.php’);
    dbDelta($sql);
 *  add_option(“utddb_version”, $utddb_version);
    }
 * ?>
 * ANY IDEAS 8O(

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Stefan M.](https://wordpress.org/support/users/stefan-m-1/)
 * (@stefan-m-1)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/wpdb-installing-custom-table-plugin/#post-2422020)
 * FILE 1: TRADEREGISTRATIONFORM.PHP
 * > <?php
   > /*
   >  Plugin Name: Trade Registration Form Extend here all the information not
   > only the single line!! */
   > register_activation_hook(__FILE__,’utddb_install’);
   >  register_uninstall_hook(
   > __FILE__,’utddb_deinstall’); // This Hooks should activate the utddb_install()
   > function which is not included in this file.. // Add the UTDDB_INSTALL.PHP 
   > with include().
   > ?>
 * FILE 2: UTDDB_INSTALL.PHP
 * > <?php
   >  $utddb_version = “1.0”; function utddb_deinstall () { global $wpdb; 
   > $tablename = $wpdb->prefix . “user_trade_details”; $sql = “DROP TABLE ‘$tablename'”;
   > $wpdb->get_row($sql); delete_option(“utddb_version”); } function utddb_install(){
   > global $wpdb,$utddb_version;
   >  $tablename = $wpdb->prefix . “user_trade_details”;
   >  $sql = “CREATE TABLE ‘$tablename’ (
   >  ‘company_id’ bigint(20) NOT NULL AUTO_INCREMENT,‘
   > user_id’, bigin(20) ‘firstname’ varchar(60) NOT NULL, ‘lastname’ varchar(60)
   > NOT NULL, ‘contactno’ bigint(15) NOT NULL, ‘company_name’ varchar(100) NOT 
   > NULL, ‘customer_type’ char(1) NOT NULL, ‘address_1’ text, ‘address_2’ text,‘
   > town’ text, ‘county’ text, ‘post_code’ text, ‘registration_date’ datetime, ‘
   > company_no’ bigin(20) );”;
   >  $wpdb->get_row($sql);
   >  add_option(“utddb_version”, $utddb_version); } ?>
 *  Thread Starter [michover](https://wordpress.org/support/users/michover/)
 * (@michover)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/wpdb-installing-custom-table-plugin/#post-2422269)
 * Thank you so much for this – I’m going to test now – thanks again for your time!!!!!!!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘$wpdb | installing custom table plugin’ is closed to new replies.

## Tags

 * [register_activation_hook](https://wordpress.org/support/topic-tag/register_activation_hook/)
 * [wpdb](https://wordpress.org/support/topic-tag/wpdb/)

 * 2 replies
 * 2 participants
 * Last reply from: [michover](https://wordpress.org/support/users/michover/)
 * Last activity: [14 years, 5 months ago](https://wordpress.org/support/topic/wpdb-installing-custom-table-plugin/#post-2422269)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
