How to insert a query into a wordpress database

I have an email subscription to my site and I want to insert into my Wordpress database so that I can export the list of email addresses. I have already created a wp_email_subscription table with 4 field identifiers, name, email and date. What will be the request for this? is there any wordpress script database to use?

+7
source share
5 answers
$wpdb->query("INSERT INTO wp_email_subscription (name, email, date) VALUES ('$name', '$email', '$date')"  );

This is if you want to insert values ​​into your table. You do not need to use $ wpdb-> email_subscription for the prefix, since this is a table that you created yourself, otherwise, if you paste the values ​​into WordPress tables by default, you would prefer to make $ wpdb-> users, etc.

+14
source

Wordpress provides a class of functions $wpdbfor interacting with a database.

To insert an email address, you can do something like:

<?php 

  $wpdb->insert('wp_email_subscription', 
    array(
      'name'          => 'name',
      'address'       => 'name@email.com'
    ),
    array(
      '%s',
      '%s'
    ) 
  ); 

?> 

Learn more about Wordpress Codex .

+12
source

You can go

global $wpdb;
$wpdb->insert('wp_email_subscription',array('name'=>$name,'email'=>$email),array('%s','%s'));

go through this for a better understanding:

http://codex.wordpress.org/Class_Reference/wpdb

+6
source
 global $wpdb

 $wpdb->insert('wp', array(
                        'email' => $_POST['email'],
                        'city'  =>   $_POST['city'],
                        'state' =>$_POST['state'],
                        'phone' => $_POST['phone'],
                       'mobile' => $_POST['mobile'],
                       )
             );
+1
source
function insert($array = false)
{
    global $wpdb;
    return $wpdb->insert($wpdb->prefix . 'email_subscription', $array);
}
+1
source

All Articles