<?php
 ob_start();
 add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
 function my_theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'style', get_stylesheet_uri());
//date picker................
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_style('jquery-ui-css', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
}
//customer details form
function customer_deatails_insert_into_db(){
global $wpdb,$productname,$quantity,$total,$price;
global $woocommerce,$product;
$html = ob_get_clean();
// creates table1 in database if not exists
$table = $wpdb->prefix . "customer_order_details"; 
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE IF NOT EXISTS $table (
    `id` mediumint(9) NOT NULL AUTO_INCREMENT,
    `givenname` text NOT NULL,
    `familyname` text NOT NULL,
    `email` varchar(50) NOT NULL,
    `number` int NOT NULL,
    PRIMARY KEY  (id),
UNIQUE (`id`)
) $charset_collate;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
//$wpdb->query($sql) or die(mysql_error());
dbDelta( $sql );
//  creates table1 in database if not exists
$table1 = $wpdb->prefix . "product_order_details"; 
$charset_collate = $wpdb->get_charset_collate();
$sql1 = "CREATE TABLE IF NOT EXISTS $table1 (
    `id` mediumint(9) NOT NULL AUTO_INCREMENT,
    `date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `productordername` text NOT NULL,
    `productorderweight` int NOT NULL,
    `orderprice` int NOT NULL,
    `orderquantity` int NOT NULL,
    `totalorder` int NOT NULL,
     `customer_email` text NOT NULL,
    PRIMARY KEY  (id),
UNIQUE (`id`)
) $charset_collate;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
//$wpdb->query($sql) or die(mysql_error());
dbDelta( $sql1 );
}
add_shortcode( 'insert_into_db', 'customer_deatails_insert_into_db' );
ob_flush();

I am using cakes and bakes rare theme.
I have created a child theme (bakes-and-cakes-child)
The above code is inside the bakes-and-cakes-child/functions.php
when I lexecute a page there is no (customer_order_details and product_order_details) tables created in database and debug.log show error

“Undefined offset: 1 in /home/………./includes/dashboard.php on line 1227”

Anybody please help me?

Read more here: Undefined offset: 1 in /home/………./includes/dashboard.php on line 1227 in wordpress


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: