how to insert data in database in wordpress plugin Using the $wpdb->insert(), This article describes how to have your plugin automatically create a MySQL/MariaDB table to store its data.
how to insert data in database in wordpress plugin
Using the $wpdb->insert()
function getAccountInfo() { global $wpdb; $table_name = $wpdb->prefix . 'pakainfo_v1'; $wpdb->insert($table_name, array('column_1' => $invocie_number, 'column_2' => $subscriptions, //other columns and data (if available) ...)); }
function mySecondFunction() { global $wpdb; $table_name = $wpdb->prefix . 'pakainfo_v1'; $commnets = 'Another method of insert.'; $date = date('Y-m-d H:i:s'); $wpdb->query("INSERT INTO $table_name(content_id, content_message, content_date) VALUES(NULL, '$commnets', '$date')"); }
create table and insert data in wordpress plugin
create table in wordpress plugin
<?php function table_create() { global $wpdb; $table_name = $wpdb->prefix . "api_wp_info"; $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE IF NOT EXISTS $table_name ( id mediumint(9) NOT NULL AUTO_INCREMENT, name tinytext NOT NULL, email tinytext NOT NULL, number tinytext NOT NULL, shop_domain text NOT NULL, PRIMARY KEY (id) ) $charset_collate"; require_once( ABSPATH .'wp-admin/includes/upgrade.php' ); dbDelta( $sql ); } ?>
how to create table in wordpress database?
function myplugin_update_db_check() { global $jal_db_version; if ( get_site_option( 'jal_db_version' )ย != $jal_db_version ) { jal_install(); } } add_action( 'plugins_loaded', 'myplugin_update_db_check' );
Don’t Miss : How To Insert Query In WordPress Using Wpdb? โ Examples?
create table and insert data in wordpress plugin
<?php function table_create() { global $wpdb; $table_name = $wpdb->prefix . "api_wp_info"; $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE IF NOT EXISTS $table_name ( id mediumint(9) NOT NULL AUTO_INCREMENT, name tinytext NOT NULL, email tinytext NOT NULL, number tinytext NOT NULL, shop_domain text NOT NULL, PRIMARY KEY (id) ) $charset_collate"; require_once( ABSPATH .'wp-admin/includes/upgrade.php' ); dbDelta( $sql ); } function insermember() {global $wpdb; $table_name = $wpdb->prefix . "api_wp_info"; $wpdb->insert('wp_api_wp_info', array('name'=>$name, 'email'=>$email, 'number'=>$number, 'shop_domain'=>$shop_domain), array('%s','%s')); register_activation_hook(__FILE__, 'table_create' ); register_activation_hook(__FILE__, 'insermember' ); ?>
How to insert form data in MySql database WordPress?
<?php require_once('/wp-config.php'); global $wpdb; if ( isset( $_POST['submit'] ) ){ $wpdb->insert( 'wp_post_job', array( 'profile' => $_POST['profile'], 'lname' => $_POST['lname'], 'email' => $_POST['email'], 'city' => $_POST['city'], array( '%s', '%s', '%s', '%s') ); } ?> <?php get_header(); ?> <form action="" id="postjob" method="post"> <input type="text" name="website_domain" id="website_domain" value="/> <input type="text" name="website_domain" id="website_domain" value="/> <input type="text" name="website_domain" id="website_domain" value="/> <input type="text" name="website_domain" id="website_domain" value="/> </form> <?php get_footer(); ?>
I hope you get an idea about how to insert data in database in wordpress plugin.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, donโt forget to share.