title: Wordpress insert data from front end to custom table using shortcode
body: <p>I am trying to insert data into WordPress database by creating a new table from a plugin.I use a shortcode to generate the form I have created the table but when I try to insert the data from form, it does not insert the data. Can someone help me on this? </p>
  
  <p><strong>Here is my code:-</strong></p>
  
  <pre><code>function insert_into_employee_db() {
          global $wpdb;
          $page_link = get_permalink();
  
          // starts output buffering
          ob_start();
          ?&gt;
          &lt;style&gt;
          form#v_form&gt;input {
              margin: 5px;
          }
          &lt;/style&gt;
          &lt;form action="" method="post" id="v_form"&gt;
  
              &lt;input type="text" name="total_employee" id="total_employee" placeholder="Total Employee" /&gt;
              &lt;input type="text" name="present_employee" id="present_employee" placeholder="Present Today" /&gt;
              &lt;input type="text" name="br_manager" id="br_manager"  placeholder="Manager Name"/&gt;
              &lt;input type="number" name="br_code" id="br_code"  placeholder="Branch Code"/&gt;
              &lt;input type="text" name="br_name" id="br_name"  placeholder="Branch Name"/&gt;
  
              &lt;input type="submit" name="submit_form" value="submit" /&gt;
          &lt;/form&gt;
          &lt;?php
          $html = ob_get_clean();
          // does the inserting, in case the form is filled and submitted
          if ( isset( $_POST["submit_form"] ) &amp;&amp; $_POST["total_employee"] != "" ) {
              $tablename = $wpdb-&gt;prefix."sbl_employee";
  
              $time               = date("d/m/Y");
              $total_employee     = $_POST["total_employee"];
              $present_employee   = $_POST["present_employee"];
              $br_manager         = $_POST["br_manager"];
              $br_code            = $_POST["br_code"];
              $br_name            = $_POST["br_name"];
              $data = array(
                          'time'              =&gt; date('dd-mm-YY'),
                          'total_employee'    =&gt; (int)$total_employee,
                          'present_employee'  =&gt; (int)$present_employee,
                          'br_manager'        =&gt; $br_manager,
                          'br_code'           =&gt; (int)$br_code,
                          'br_name'           =&gt; $br_name,
                         );
  
  
              $format = array(
                  '%s', '%s', '%s', '%s', '%s', '%s'
              );
              $success=$wpdb-&gt;insert( $tablename, $data, $format );
              if($success){
                  $html = "&lt;p&gt;Successfully Saved. &lt;a href=".$page_link."&gt;Update? &lt;/a&gt;&lt;/p&gt;";
              }else{
                  $html = "failed. ". $wpdb-&gt;show_errors();
              }
          }
          // if the form is submitted but the name is empty
          if ( isset( $_POST["submit_form"] ) &amp;&amp; $_POST["total_employee"] == "" )
              $html .= "&lt;p&gt;You need to fill the required fields.&lt;/p&gt;";
          // outputs everything
          return $html;
      }
      // adds a shortcode you can use: [insert-employee]
      add_shortcode('insert_employee', 'insert_into_employee_db');
  </code></pre>
  
  <p><strong>and here is my db create function</strong></p>
  
  <pre><code>function sbl_employee_create_db() {
  
      global $wpdb;
  
      $charset_collate = $wpdb-&gt;get_charset_collate();
      $table_employee  = $wpdb-&gt;prefix . 'sbl_employee';
      $table_br_name   = $wpdb-&gt;prefix . 'sbl_br_name';
  
      $sql = "CREATE TABLE IF NOT EXISTS $table_employee (
          id mediumint(9) NOT NULL AUTO_INCREMENT,
          time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
          total_employee smallint(5) NOT NULL,
          present_employee smallint(5) NOT NULL,
          br_manager varchar(5) NOT NULL,
          br_code smallint(5) NOT NULL,
          br_name varchar(120) NOT NULL,
          UNIQUE KEY id (id)
      ) $charset_collate;";
  
      require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
      dbDelta( $sql );
  }
  //do action when plugin active
  register_activation_hook( __FILE__, 'sbl_employee_create_db' );
  </code></pre>