a insert query in wordpress

We can use insert query in wordpress as follows.Just take a look on query.It is quite simple as we use in php to insert data into database.

<?php
global $wpdb;

$wpdb->prepare(
 "INSERT INTO `wp_submitted_form` 
   (`name`,`email`,`phone`,`country`,`course`,`message`,`datesent`) 
   values ('$name', '$email', '$phone', '$country', 
         '$course', '$message', '$datesent')"
 );
?>

Or,

use can use query in this way also

<?php $wpdb->insert('table_name', input_array()); ?>

like

<?php
global $wpdb;
$wpdb->insert("wp_submitted_form", array(
   "name" => $name,
   "email" => $email,
   "phone" => $phone,
   "country" => $country,
   "course" => $course,
   "message" => $message,
   "datesent" => $now ,
));
?>

Leave a Comment