unable to insert data into wordpress db using form

When i click on submit it doesn’t create new posts in the posttype. It just refreshes the page.The below is a pagetemplate assigned to page.

<?php
    if(isset($_POST['submit'])){
    global $wpdb;
    $wpdb->insert( 'contacts', array('post_title'=>$_POST['name'],'email'=>$_POST['email']));
    }
?>
<form method="post" action="">
<input type="name" id="inputName" placeholder="Name">
<input type="email" id="inputEmail" placeholder="Email">
<button type="submit">SUBMIT</button>
</form>


Source: wpdb

Leave a Reply