insert data in database table from plugin with WP3.1
I am quite new in WP Plugin World. I am trying to develop a plugin in WP 3.1 when I am trying to insert data into my table named "wp_enam
" in the following way:
$wpdb-insert($wpdb-enam, array('username' = "enam" ,
'useremail' = "[email protected]"));
it is not working.
I try to debug it in following way:
$wpdb-show_errors();
$wpdb-insert($wpdb-enam, array('username' = "enam" ,
'useremail' = "[email protected]"));
$wpdb-print_error();
Now I am getting following message from MR.WP
WordPress database error: [Incorrect table name '']
INSERT INTO `` (`username`,`useremail`) VALUES ('enam','[email protected]')
WordPress database error: [Incorrect table name '']
INSERT INTO `` (`username`,`useremail`) VALUES ('enam','[email protected]')
As you can see the table name is not showing in the mysql query. Is this a correct way to access a table name with $wpdb-my_table
? I am using mysql. Thanks in advance.
Edit 1:
Looks like $wpdb-tblname
do not add the table prefix anymore! As per "Professional WordPress Wrox" by Hal Stern, David Damstra and Brad Williams" (which is a great book ) it should work. The above functionality is explained at this book in the following way:
$wpdb-my_custom_table to reference the table in WordPress.
This translates to wp_my_custom_table if wp_ is the table prefix.
This is the proper way to determine the correct table prefix when working with tables in the WordPress database.
(Page:107)