title: if ($_SERVER["REQUEST_METHOD"] == "POST") condition not getting satisfied after ajax call to different php file for validations and submitting form
body: <p>I have registration page as below where I'm posting back to same page.</p>
  
  <pre><code>&lt;?php
      session_start();
      if ($_SERVER["REQUEST_METHOD"] == "POST") {
          $_SESSION["registered"] = "success";
          $count = insert_record($_POST['fname'],$_POST['lname'],$_POST['email'],$_POST['regusername'],$_POST['regpassword']);
          header("Location: login.php");
      }
      $page_title = "Registration";
      if(isset($_SESSION["username"]))
          include('includes/header_authorized.html');
      else
          include('includes/header.html');
  
  ?&gt;
  
  &lt;div class="container"&gt;
      &lt;div class="regform"&gt;
          &lt;form  name="registration" id="registration" method="post" action="registration.php"&gt;
              &lt;p&gt;&lt;span class="req"&gt;* required field.&lt;/span&gt;&lt;/p&gt;                      
              &lt;ul&gt;
                  &lt;li&gt;&lt;label for="fname"&gt;First Name:&lt;/label&gt;
                      &lt;input type="text" class="textboxborder" id="fname" name="fname" size="20" maxlength="25" autofocus="autofocus" value="&lt;?php if(isset($_POST['fname'])) echo $_POST['fname'];?&gt;"/&gt;
                      &lt;span class="error" id="errfname"&gt;*&lt;?php if(isset($errfname)) echo $errfname;?&gt;&lt;/span&gt;
                  &lt;/li&gt;
                  &lt;li&gt;&lt;label for="lname"&gt;Last Name:&lt;/label&gt;
                      &lt;input type="text" class="textboxborder" id="lname" name="lname" size="20" maxlength="25" value="&lt;?php if(isset($_POST['lname'])) echo $_POST['lname'];?&gt;"/&gt;
                      &lt;span class="error" id ="errlname"&gt;*&lt;?php if(isset($errlname)) echo $errlname;?&gt;&lt;/span&gt;
                  &lt;/li&gt; 
                  &lt;li&gt;&lt;label for="email"&gt;Email:&lt;/label&gt;
                      &lt;input type="text" class="textboxborder" name="email" id="email" size="40" maxlength="50" placeholder="abc@xyz.com" value="&lt;?php if(isset($_POST['email'])) echo $_POST['email'];?&gt;"/&gt; 
                      &lt;span class="error" id="erremail"&gt;*&lt;?php if(isset($erremail)) echo $erremail;?&gt;&lt;/span&gt;  
                  &lt;/li&gt;
                  &lt;li&gt;&lt;label for="regusername"&gt;Username:&lt;/label&gt;
                      &lt;input type="text" name="regusername" id="regusername" size="20" maxlength="30" value="&lt;?php if(isset($_POST['regusername'])) echo $_POST['regusername'];?&gt;"/&gt; 
                      &lt;span class="error" id="errregusername"&gt;*&lt;?php if(isset($errregusername)) echo $errregusername;?&gt;&lt;/span&gt; 
                  &lt;/li&gt;
                  &lt;li&gt;&lt;label for="regpassword"&gt;Password:&lt;/label&gt;
                      &lt;input type="text" name="regpassword" id="regpassword" size="20" maxlength="15" value="&lt;?php if(isset($_POST['regpassword'])) echo $_POST['regpassword'];?&gt;"/&gt; 
                      &lt;span class="error" id="errregpassword"&gt;*&lt;?php if(isset($errregpassword)) echo $errregpassword;?&gt;&lt;/span&gt; 
                  &lt;/li&gt;
                  &lt;li&gt;&lt;label for="regconpassword"&gt;Confirm Password:&lt;/label&gt;
                      &lt;input type="text" name="regconpassword" id="regconpassword" size="20" maxlength="15"/&gt; 
                      &lt;span class="error" id="errregconpassword"&gt;*&lt;?php if(isset($errregconpassword)) echo $errregconpassword;?&gt;&lt;/span&gt; 
                  &lt;/li&gt;
              &lt;/ul&gt;
              &lt;div id="message_line"&gt;&amp;nbsp;&lt;?php if(isset($error)) echo $error;?&gt;&lt;/div&gt;
              &lt;div class="buttons"&gt;
                  &lt;input type="reset" value="Reset" id="reset"/&gt;
                  &lt;input type="submit" value="Submit" id="submit"/&gt;
              &lt;/div&gt; 
          &lt;/form&gt;  
          &lt;img src="images/loading.gif" id="busy_wait" alt="busy wait icon" /&gt;  
      &lt;/div&gt; 
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>In javascript I validate that the user is no duplicate and submit the form (I debugged it works fine, <code>$('#registration').submit();</code> gets executed) </p>
  
  <pre><code>$('#submit').on('click', function(e) {  
          $('#message_line').text("");    
          if(validate_fields_on_submit()) {
              e.preventDefault();
              return;
          }   
          var params = $('form').serialize();      
          var url = "check_duplicate.php?" + params;
          var request = new HttpRequest(url, submitHandler);
          request.send(params);
          $('#busy_wait').css('display','block');
          e.preventDefault(); 
      });
      function submitHandler(response) {
          $('#message_line').text("");    
          response = $.trim(response);
          if(response == "" &amp;&amp; response.indexOf("&lt;") &lt;= -1)
              $('#registration').submit();
          else if(response.indexOf("&lt;") == 0) {
              var name = $('[name="regusername"]').val();
              $('#message_line').text("Some error occured, please try after some time.");  
              $("#message_line").attr("tabindex",-1).focus();   
          } else {   
              var name = $('[name="regusername"]').val();
              var arr = response.split(',');
              arr.pop();
              arr.toString();
              $('#message_line').text("'" + name + "' already exists, Please try different username");  
              $("#regusername").focus();  
          }                                    
          $('#busy_wait').css('display','none');   
      }
  </code></pre>
  
  <p>In insert_record this is what I have -</p>
  
  <pre><code>function insert_record($fname,$lname,$email,$username,$password) {
      $conn = get_connection();
      $to_insert = "INSERT INTO user VALUES ('$fname', '$lname', '$email', '$username', '$password', 20)";
      if(!($result = mysqli_query($conn,$to_insert)))
          return 0;                       
      else
          return mysqli_affected_rows($conn);
  } 
  </code></pre>
  
  <p>For some reason when I click submit nothing happens after validation of duplicate user.</p>
  
  <p>If I remove ajax call to check duplicate and submit it directly it is working fine.
  Please suggest what I might be doing wrong.</p>