Can't find out why dbDelta dosen't create my table

I have a function which needs to create a new table an d i can't see for the life of me why it dosen't create the table: function afdv_create_delivery_table ( $id ){ global $wpdb; $charset_collate = $wpdb->get_charset_collate(); //table name composed of db prefix + delivery + company ID $table_name = $wpdb->prefix . "delivery_" . $id; $sql = "CREATE TABLE $table_name ( id int(10) unsigned NOT NULL AUTO_INCREMENT, userId int(10) NOT NULL, plati DECIMAL(10,2) NOT NULL, incasariCash DECIMAL(10,2) NOT NULL, incasariPvo …
Category: Web

dbDelta ALTER TABLE syntax?

Due to some changes in the DB, I need to alter a table to add one column to it, but even though the function is running, the table isn't altered. Here's the ALTER TABLE code that I've written $sql = "ALTER TABLE " . $packagetable . " ADD COLUMN price decimal(14,2) NOT NULL AFTER description;"; dbDelta($sql); I couldn't find the syntax for ALTER TABLE with dbDelta anywhere online. EDIT: After looking at the ALTER TABLE statement in gravity forms plugin, …
Category: Web

How to store sensitive user data (passwords)

I want to create a plugin addon that allows my sites users to share private login information in a secure manner. So they'll enter these private details in a form on the frontend and I want to be able to decrypt it on the backend. What's the best way to go about this, because as far as I'm aware password encrypting is a one-way process, or will I be able to use encrypt() or password ()?
Category: Web

CREATE TABLE with dbDelta does not create table

I based this code from the codex on the docs. I placed it in my main plugin file but it's not creating the database table. Have I missed something? // Database setup and hooks function core_createdb() { global $wpdb; $table_name = $wpdb->prefix . 'core_logs'; $wpdb_collate = $wpdb->collate; $sql = "CREATE TABLE {$table_name} ( timestamp DATE NOT NULL, logid INT NOT NULL AUTO_INCREMENT, userid INT DEFAULT NULL, actiontype TINYTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT 'undefined', userip VARCHAR CHARACTER SET utf8mb4 …
Category: Web

dbDelta only creates the last table

I'm using following install function with dbDelta as referring to the codex, articles on SO I watched out for the typical problems with e.g. one space instead of two spaced at the PRIMARY KEY ... function myplugin_install(){ global $wpdb; $table_name = $wpdb->prefix . "vehicles"; $sql = "CREATE TABLE IF NOT EXISTS $table_name ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, description VARCHAR(25) NOT NULL, PRIMARY KEY (id) ); "; $sql .= "CREATE TABLE IF NOT EXISTS $table_name1 ( ... )"; $sql …
Category: Web

Adding a Table to the wordpress database

I am using the following script to add a table to the wordpress database, but nothing is happening. I am not sure what I am doing wrong. Any advice would be much appreciated. function vw_postcode_checker_create_db () { global $wpdb; global $tableprefix; // Create Table Name $table_name =$tableprefix . "vw_postcode_checker"; // Write Query to add table to database if ($wpdb->get_var('SHOW TABLES LIKE'.$table_name) !=$table_name) { $sql = "CREATE TABLE " . $table_name . " ( id INTEGER(10) UNSIGNED AUTO_INCREMENT, postcode varchar(250) NOT …
Category: Web

The function can not create a table on MariaDB server

The function works on MySQL server well but it can not create a table on the MariaDB server. What could be the problem? public function create_table() { $current_version = get_option('wpsm_db_table_version'); if($current_version && $current_version == $this->db_version && $this->db->get_var("SHOW TABLES LIKE '$this->table_name'") == $this->table_name){ return; } $sql = "CREATE TABLE ". $this->table_name ." ( id bigint(20) unsigned NOT NULL auto_increment, name varchar(255) NOT NULL default '', rows int(11) NOT NULL default 0, cols int(11) NOT NULL default 0, subs varchar(255) NOT NULL …
Category: Web

cant insert data in a custom table in phpmyadmin

i created a dbdelta table but i cant seem to insert any data here is my code please help function lapizzeria_save_reservation() { global $wpdb; if(isset($_POST['reservation']) && $_POST['hidden'] =="1") { $name =$_POST['name']; $date =$_POST['date']; $email =$_POST['email']; $phone =$_POST['phone']; $message =$_POST['message']; $table = $wpdb->prefix . 'reservations'; $data = array( 'name' => $name, 'date' => $date, 'email' => $email, 'phone' => $phone, 'message' => $message ); $format = array( '%s', '%s', '%s', '%s', '%s' ); $wpdb->insert($table, $data, $format); } } add_action('init', 'lapizzeria_save_reservation'); here …
Category: Web

dbDelta not CREATING TABLE

Here's my code. Please help function lapizzeria_database() { global $wpdb; global $lapizzeria_db_version; $lapizzeria_db_version = "1.0"; $table = $wpdb->prefix . 'reservation'; $charset_collate = $wpdb->get_charset_collate(); //SQL Statement $sql = "CREATE TABLE $table ( id mediumint(9) NOT NULL AUTO_INCREMENT, name varchar(50) NOT NULL, date datetime NOT NULL, email varchar(50) DEFAULT '' NOT NULL, phone varchar(10) NOT NULL message longtext NOT NULL, PRIMARY KEY (id) ) $charset_collate; "; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); } add_action('after_setup_theme', 'lapizzeria_database');
Category: Web

dbDelta not creating tables

I went through a lot of threads, codex page and tried messing with a lot of things but my code doesn't seem to be creating the tables. And I am not able to figure out where I am going wrong. I checked booking_db_version in the database, it gets updated when I update it in the file. Here's the code global $booking_db_version; $booking_db_version = "1.0.0"; function booking_install() { global $wpdb; global $booking_db_version; global $tableprefix; $installed_version = get_option('booking_db_option'); $tableprefix = $wpdb->prefix . …
Category: Web

Fatal error: Call to undefined function dbDelta()

I want to create a table during the activation of the plugin, so I used the code as follows: class Database { private $db_version = '1.0', $table_prefix; public function __construct() { global $wpdb; $this->table_prefix = $wpdb->prefix; register_activation_hook( PLUGIN_INDEX_FILE, array($this, 'dbSetup') ); } public function dbSetup() { $countriesSQL = "CREATE TABLE $this->table_prefix . countries ( id int(11) UNSIGNED NOT NULL, country_code varchar(2) NOT NULL DEFAULT '', country_name varchar(100) NOT NULL DEFAULT '', PRIMARY KEY (id) ) $charset_collate;"; dbDelta( $countriesSQL ); } …
Category: Web

dbDelta with the character ;

To manage database plugin update, I changed my code using dbDelta. old code myfunction(){ ... $query_string = "INSERT INTO {$table_name} {$str_column_names} VALUES {$str_values}"; $is_data_inserted = $wpdb->query( $query_string ); if( !$is_data_inserted ){ $message_error = sprintf( "impossible to insert the data %s for the table %s!", serialize( $data_item_attrs ), $table_name ); $wpdb->show_errors(); wp_error_log( $message_error, "Insert Data Error" ); return false; } return true; } new code myfunction(){ ... $query_string = "INSERT INTO {$table_name} {$str_column_names} VALUES {$str_values}"; dbDelta( $query_string ); } My problem …
Category: Web

Create table with dbDelta,can't put any DEFAULT data

I want to add more custom tables to wp_users. but I want them to contain a default JSON data. This one works...when the DEFAULT is empty... register_activation_hook(__FILE__, 'toto_user_db_setup'); function toto_user_db_setup() { global $wpdb; $user_data = "wp_users"; $charset_collate = $wpdb->get_charset_collate(); $game_1 = "CREATE TABLE $user_data ( data1 tinytext DEFAULT '' NOT NULL, data2 tinytext DEFAULT '' NOT NULL, data3 mediumtext DEFAULT '' NOT NULL, data4 mediumtext DEFAULT '' NOT NULL, data5 longtext DEFAULT '' NOT NULL ) $charset_collate;"; require_once( ABSPATH . …
Category: Web

Creating a database in my plugin not working

Good day everyone, I've been trying to add a table in my database for a whole day now, and I can't seem to find the error, I looked into multiple similar questions, but I had my syntax similar to all of them, and I followed the Codex when adding dbDelta(). <?php if( !function_exists('transaction_draft_save') ){ //1, 234, donation, monday june 5 2018, give monthly, 10, usd, incomplete function transaction_draft_save($user_id, $full_name, $email, $invoiceNumber, $plan_type, $date, $membership_type, $plan_price, $currency, $status){ global $taylormemorial_options; global …
Category: Web

Plugin: register_deactivation_hook works perfectly well, while register_activation_hook suddenly stopped working

So interestingly, I moved my main plugin file into a folder within the plugin directory. Where before the register_activation_hook worked perfectly well, it now does not work; however, the register_deactivation_hook still works perfectly, and it is currently being called from within the same file. I have attempted explicitly defining a path as well for the activation hooks instead of just relying on the __FILE__ keyword. Any insight that can be offered as to why the plugin no longer calls to …
Category: Web

dbDelta not creating table (yes, once more)

I KNOW there are other posts relating to my issue, i read all of them and tried to see if the answer would change and tried a few ones, but I can't seem to create my table using it. Here's my code (function is in object) and my sql querry: public static function mq_install(){ global $wpdb; require_once(constant('ABSPATH') . 'wp-admin/includes/upgrade.php'); $table_name = $wpdb->prefix . 'zebra_musiquote'; $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE " . $table_name . "( id mediumint(9) NOT NULL …
Category: Web

dbDelta not adding additional columns in plugin database update

I'm trying to update my database by adding an extra column field. However, dBdelta does not seem to be doing its job. I'm not sure what am I doing wrong. <?php function installer(){ include('installer.php'); } register_activation_hook( __file__, 'installer' ); //executes installer php when installing plugin to create new database //database update checkdate function myplugin_update_db_check() { global $xenonresult_db_version; if ( get_site_option( 'xenonresult_db_version' ) != $xenonresult_db_version ) { installer(); } } add_action( 'plugins_loaded', 'myplugin_update_db_check' ); Here is the installer.php <?php global $wpdb; …
Category: Web

Custom database table for plugin not creating on activation

Let me start by saying I know there are other posts about this, and a lot of documentation is available for this topic, but none of these resources have helped me to solve my issue. I'm a beginner at creating plugins for WordPress. This is my first, so I'm sure I'm missing something simple, but everything I have read says this should be working. The plugin activates no problem, my menu shows up, etc. But the following does not create …
Category: Web

Unable to create new database table upon plugin activation using dbDelta

I'm trying to create a new database table when my plugin is activated using dbDelta() however, no new table seems to be creating. Since I'm new to WordPress development, please let me know where I'm going wrong. <?php /* Plugin Name: Xenon-Result Plugin URI: https://developer.wordpress.org/plugins/the-basics/ Description: Basic WordPress Plugin Header Comment Version: 1.0 Author: Himanshu Gupta Author URI: https://developer.wordpress.org/ License: GPL2 License URI: https://www.gnu.org/licenses/gpl-2.0.html */ function installer(){ include('installer.php'); } register_activation_hook( __file__, 'installer' ); //executes installer php when installing plugin to …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.