I am trying to create a custom plugin in wordpress where i create a table and insert data using the pluging.Table is created successfully
But data not inserted into the table.
Here is my code
global $jal_db_version;
$jal_db_version = "1.0";
function jal_install() {
global $wpdb;
global $jal_db_version;
$table_name = $wpdb->prefix . "demo1";
$sql = "CREATE TABLE IF NOT EXISTS $table_name (
id int(9) NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
email varchar(255) NOT NULL,
password varchar(255) NOT NULL,
PRIMARY KEY id (id)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;";
$wpdb->query($sql);
pu_insert_custom_table($table_name);
}
function pu_insert_custom_table($table_name)
{
global $wpdb;
$wpdb->insert(
'$table_name',
array(
'name'=>'abc',
'email'=>'abc@gmail.com',
'password'=>'123456'
),
array(
'%s',
'%s',
'%s'
)
);
}
You need to modify your insert query as :
You can give it a try :
And then call these functions separately with wordpress hooks like this :
Taken from http://codex.wordpress.org/Creating_Tables_with_Plugins