Custom form that store input in database

I got the problem solution myself. See the code below this will do that.

Put the code inside your newly created custom template.

<?php
    if (!empty($_POST)) {
        global $wpdb;
        $table = wp_achord;
        $data = array(
            'name' => $_POST['yourname'],
            'chord'    => $_POST['chord']
        );
        $format = array(
            '%s',
            '%s'
        );
        $success=$wpdb->insert( $table, $data, $format );
        if($success){
            echo 'data has been save' ; 
        }
    } else {
        ?>
        <form method="post">
            <input type="text" name="yourname">
            <textarea name="chord"></textarea>
            <input type="submit">
        </form>
        <?php 
    }  
?>

Leave a Comment