Not able to save values into database using wordpress

I am a beginner and wanted the insert the values into the database from a custom template page but the values are not stored.

This is my code

<?php
function contact_form() {

$name   = $_POST['name'];
$email  = $_POST['email'];
$subject  = $_POST['subject'];
$comment  = $_POST['comment'];

global $wpdb;
$table_name = $wpdb->prefix . "wp_contact";
$wpdb->insert($table_name, array(
    'name' => $name, 
    'email' => $email,
    'subject' => $subject,
    'comment' => $comment
),array(
    '%s',
    '%s',
    '%s',
    '%s')
);
}

if( isset($_POST['submit']) ) contact_form();
?>

Read more here: Not able to save values into database using wordpress

Leave a Reply

Your email address will not be published. Required fields are marked *