title: Why query is firing two times in wordpress?
body: <p>I have written one code which will save the form data in database on submit...</p>
  
  <pre><code>if(isset($_POST['submitted']) &amp;&amp; ($_SERVER['REQUEST_METHOD'] == 'POST')) {
  
      global $wpdb;
      $company_name = $wpdb-&gt;prefix . "company";
      $single_table = $wpdb-&gt;prefix . "single";
      $emp_table = $wpdb-&gt;prefix . "employee";
      $idea_table = $wpdb-&gt;prefix . "idea";
  
      if($_POST['team-type'] == "Freelancer"){
          $wpdb-&gt;query( $wpdb-&gt;prepare("INSERT INTO $company_name (name, team_size) VALUES(%s, %d)", $_POST['cname'],1));  
  
  
          $company_id = $wpdb-&gt;get_var( "SELECT MAX(id) FROM wp_company" );
          echo "&lt;h2&gt;1&lt;/h2&gt;";
  
          $wpdb-&gt;query( $wpdb-&gt;prepare("INSERT INTO $single_table (company_id, name, bio,linkedin_url) VALUES (%d, %s, %s, %s)", $company_id, $_POST['freelancer-name'] ,$_POST['free-bio'], $_POST['free-url'] ) );
  
      }else{
          $query = "INSERT INTO $table_name (name, team_size) VALUES('" . $_POST['cname'] . "'," . $_POST['team'] .")";
          $wpdb-&gt;query($query);
          echo "&lt;h2&gt;2&lt;/h2&gt;";
      }
      echo "&lt;h2&gt;3&lt;/h2&gt;";
  }
  </code></pre>
  
  <p>The problem is, in database the data is stored twice.</p>
  
  <p>But the h2 tag which i put on page, that is showing only one time.</p>
  
  <p>What's wrong in code or what should i do to save data only one time ?</p>
  
  <p>BTW the if condition is also working fine, bcz i can check the h2 tags on based what i select ?</p>