adding custom tables to wordpress :: 2018-01-16 15:20:24


function booking_install() {
global $wpdb;
//global $booking_db_version;
//global $tableprefix;
//$installed_version = get_option('booking_db_option');

if(isset($_GET['add_database_table_submit'])):
echo "submission event started...";
$packages = $_GET['packages'];
$hotels = $_GET['hotels'];
$addons = $_GET['addons'];
$addon_groups = $_GET['addon_groups'];
echo "User Has submitted the form and entered this package : <b> $packages </b>";
echo "User Has submitted the form and entered this hotels : <b> $hotels </b>";
echo "User Has submitted the form and entered this addons : <b> $addons </b>";
echo "User Has submitted the form and entered this addon_groups : <b> $addon_groups </b>";
endif;
?&gt;

<form id="add_database_table_form" action="&lt;?php echo $_SERVER&#91;'PHP_SELF'&#93;; ?&gt;&lt;p&gt;" method="get">
<div class="form-group"><label for="packages">packages</label>
<input id="packages" class="form-control" name="packages" type="text" placeholder="packages" /></div>
<div class="form-group"><label for="hotels">hotels</label>
<input id="hotels" class="form-control" name="hotels" type="text" placeholder="hotels" /></div>
<div class="form-group"><label for="addons">addons</label>
<input id="addons" class="form-control" name="addons" type="text" placeholder="addons" /></div>
<div class="form-group"><label for="addon_groups">addon_groups</label>
<input id="addon_groups" class="form-control" name="addon_groups" type="text" placeholder="addon_groups" /></div>
<input id="add_database_table_submit" class="btn btn-primary" name="add_database_table_submit" type="submit" />Submit

</form><!--?php $tableprefix = $wpdb-&gt;prefix;&lt;br ?--> $wpdb_collate = $wpdb-&gt;collate;

//if ( $installed_version !== $booking_db_version ) :
// Create table for packages
$packagetable = $tableprefix . $packages;
if($wpdb-&gt;get_var("SHOW TABLES LIKE '{$packagetable}'") != $packagetable) :
$sql = "CREATE TABLE {$packagetable} (
recID mediumint(8) unsigned NOT NULL auto_increment ,
name varchar(255) NULL,
description varchar(255) NULL,
city1 varchar(255) NULL,
city2 varchar(255) NULL,
PRIMARY KEY (recID),
KEY name (name)
)
COLLATE {$wpdb_collate}";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
endif;

// Create table for hotels
$hoteltable = $tableprefix . $hotels;
if($wpdb-&gt;get_var("SHOW TABLES LIKE '{$hoteltable}'") != $hoteltable) :
$sql = "CREATE TABLE {$hoteltable} (
recID mediumint(8) unsigned NOT NULL auto_increment ,
name varchar(255) NULL,
city varchar(255) NULL,
price decimal(10,2) NULL,
PRIMARY KEY (recID),
KEY name (name)
)
COLLATE {$wpdb_collate}";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
endif;

// Create table for addons
$addontable = $tableprefix . $addons;
if($wpdb-&gt;get_var("SHOW TABLES LIKE '{$addontable}'") != $addontable) :
$sql = "CREATE TABLE {$addontable} (
recID mediumint(8) unsigned NOT NULL auto_increment ,
name varchar(255) NULL,
addongroup varchar(255) NULL,
price decimal(10,2) NULL,
PRIMARY KEY (recID),
KEY name (name)
)
COLLATE {$wpdb_collate}";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
endif;

// Create table for addon groups
$addongrouptable = $tableprefix . $addon_groups;
if($wpdb-&gt;get_var("SHOW TABLES LIKE '{$addongrouptable}'") != $addongrouptable) :
$sql = "CREATE TABLE {$addongrouptable} (
recID mediumint(8) unsigned NOT NULL auto_increment ,
name varchar(255) NULL,
perhead varchar(255) NULL,
PRIMARY KEY (recID),
KEY name (name)
)
COLLATE {$wpdb_collate}";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
endif;
}
?&gt;

« »