Jump to content

Need A Fresh Pair Of Eyes


jdbfitz

Recommended Posts

The following code is NOT generating any errors .... but it is not creating the table either. Maybe I have been looking at this too long and can not see the obvious. Any thoughts? Thanks!

 

$install_table_version = "1.0";
global $wpdb;

global $install_table_version;
$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
function install_table () {

	$my_ti=getdate(date("U"));
	$current_date=("$my_ti[year]-$my_ti[mon]-$my_ti[mday]");
	$hours = $my_ti[hours];
	$minutes = $my_ti[minutes];
	$seconds = $my_ti[seconds];
	$current_time=("$hours:$minutes:$seconds");


   $table_name = $wpdb->prefix . "gluco";
   if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
      
   $sql = "CREATE TABLE " . $table_name . " (
  id mediumint(9) NOT NULL AUTO_INCREMENT,
  date1 time() DEFAULT '0' NOT NULL,
  time1 date() NOT NULL,
  level float(5,2) NOT NULL,
  fast VARCHAR(55) NOT NULL,
  comments VARCHAR(256) NOT NULL,
  num_display mediumint (9) NOT NULL,
  UNIQUE KEY id (id)
);";

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

	$date1 = $current_date;
	$time1 = $current_time;
	$level = "240";
	$fast = "No";
	$comments = "This is a test";
	$num_display = "0";


      $insert = "INSERT INTO " . $table_name .
            " (date1, time1, level, fast, comments, num_display) " .
            "VALUES ($wpdb->escape($date1), $wpdb->escape($time1), $wpdb->escape($level), $wpdb->escape($fast), $wpdb->escape($comments), $wpdb->escape($num_display))";

      $results = $wpdb->query( $insert );
      add_option("install_table_version", $install_table_version);
   }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.