Wordpress - insert data in database table from plugin with WP3.1

You can check database function for database here. For the table prefix matter you should use $wpdb->prefix . 'enam' and it will return the table prefix. Just add the table name with this. So the total code would be :

$yourtablename =  $wpdb->prefix . 'enam';

so your total code could be something like:

$wpdb->insert($yourtablename , array('username' => "enam" ,
                             'useremail' => "[email protected]"));

EDIT: If you need more information you can see THIS article. This is very useful article for creating plugin with database.


You should use something like

$wpdb->prefix . 'table_name'

instead.

If you don't wan't to repeat your table name through your code save it in a variable or create a function like this one: (nothing cool, but I use it this way, works if you have just one custom table, so it is not very versatile..)

function get_table_name() {
    global $wpdb;
    return $wpdb->prefix . 'table_name';
}