Home / Wordpress / How to insert data into WordPress database ?

How to insert data into WordPress database ?

WordPress has its own database. Sometimes we have to insert data in a custom table. You can create a custom table in WordPress database and can insert data into WordPress database.  In this example I have used $wpdb function. Here is simple script to insert data into WordPress database custom table .

<?php /* Template Name: db */
global $wpdb;
$name=’yourname’;
if($wpdb->insert(
‘dbtable’,
array(
‘name’ => $name
)
) == false) wp_die(‘Database Insertion failed’);
else echo ‘Database insertion successful<p />’;
?>

$wpdb is WordPress function to interact with database., dbtable  is the name if database  table.  In array name is inserted into name column of dbtable table.

About Abid

I am Abid Hussain a professional software developer, worked on dozens of projects specializing in web development. I also provide web development service on Fiverr and Freelancer.

Leave a Reply

Your email address will not be published. Required fields are marked *