Support » Plugins » $wpdb | installing custom table plugin

  • michover

    (@michover)



    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.

    (@stefan-m-1)

    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);
    }
    ?>

    michover

    (@michover)

    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.