title: Inserting data into wordpress table using a html form
body: <p>I am trying for hours to resolve what I thought was a simple issue but am still no further...</p>
  
  <p>Below is my code to input 3 fields into a wordpress custom table called 'std'. Not sure if it is a connection issue or my code is just wrong! when I click submit, the I am just given the "databse insertion failed" message but am not the wiser as to why. </p>
  
  <pre><code>&lt;?php
  
     /*
     Template Name:ProRata
     */
  
     //get_header();
  
      if($_POST['Submit']){
  
  
      global $wpdb;
  
      require_once('wp-config.php');
  
      $name=$POST['aname'];
      $roll=$POST['aroll'];
      $dept=$POST['adept'];
  
      $tablename = $wpdb-&gt;prefix.'std';
  
      if($wpdb-&gt;insert(
      $tablename,
  
      array(
  
  
      'name'=&gt; $name,
      'roll'=&gt; $roll,
      'dept'=&gt; $dept
      )
  
  
      ) ==false) wp_die('databse insertion failed');
      else echo 'Database insertion completed&lt;/p&gt;';
  
      ?&gt;
      &lt;?php
      }
      else // if form has not yet been submitted
      {
      ?&gt;
      &lt;br&gt;
  
      &lt;form action="" method="post"&gt;
      &lt;label&gt;Leave: Type of leave &lt;/label&gt;
  
      &lt;label&gt; aname &lt;/label&gt;
      &lt;input type="text" name="aname"&gt;&lt;br&gt;&lt;br&gt;
      &lt;label&gt; Leave: Start Date &lt;/label&gt;
      &lt;input type="text" name="aroll"&gt;&lt;br&gt;&lt;br&gt;
      &lt;label&gt; Leave: End Date &lt;/label&gt;
      &lt;input type="text" name="adept"&gt;&lt;br&gt;&lt;br&gt;
      &lt;input type="submit" name="Submit"&gt;&lt;br&gt;
  
      &lt;/form&gt;
      &lt;?php
  
      }
  
      ?&gt;
  </code></pre>