The contents can be inserted by using the function given below:
function my_plugin_insert_db() {
global $wpdb;
$username = ‘wordpress’;
$email = ‘test1@wordpress.com‘;
$table_name = $wpdb->prefix . ‘db_plugin’;
$wpdb->insert(
$table_name,
array(
‘username’ => $username,
’email’ => $email,
)
);
}
if(isset($_POST[‘button2’])) {
global $wpdb;
$username = $_POST[“fname”];
$email = $_POST[“email”];
$table_name = $wpdb->prefix . ‘db_plugin’;
$wpdb->insert(
$table_name,
array(
‘username’ => $username,
’email’ => $email,
)
);
}
We need to add this function in the file that we have created. I created it in the plugin and added this function below the function where i created the table. So while using the function make sure that we are using it in the correct position.
Also make sure that the name given to the table is also same as that we have created.