title: jQuery.post php7 incombatibility
body: <p>For a popup email form I use a script with an jQuery.post call to a php file on the same server. I have used this many times successfully, but now, since upgrading to php7, the form does not submit anymore and the Chrome Console shows a 500 error. When I'm switching back to php 5.6 all works fine. Do I have some deprecated code in this?</p>
  
  <pre><code>jQuery.post('https://www.myurl.com.au/contact_me.php', post_data, function(response){  
          // console.log( response );
          if(response.type == 'error'){ //load json data from server and output message     
              output = '&lt;div class="error"&gt;'+response.text+'&lt;/div&gt;';
          }else{
              window.location = "https://www.myurl.com.au/thank-you";
              output = '&lt;div class="success"&gt;'+response.text+'&lt;/div&gt;';
  
              //reset values in all input fields
              jQuery("#contact_form1 input[required=true]").val(''); 
              jQuery("#contact_form1 #contact_body1").slideUp(); //hide form after success
          }
          jQuery("#contact_form1 #contact_results1").hide().html(output).slideDown();
      }, 'json');
  </code></pre>
  
  <p>PHP code here:
      
  
  <pre><code>// Check first if the number id in database is even or odd.
  // Set the variable storing the email address accordingly.
  
  // Define variables used for connection to database.
  $server = "localhost"; 
  $username = "myusername";
  $password = "mypw";
  $db_name = "mydb";
  
  // Connect to server and select database
  mysql_connect($server, $username, $password) or die ("&lt;p&gt;" . "MySQL connection failed: " . mysql_error() . "&lt;/p&gt;");
  mysql_select_db($db_name) or die ("&lt;p&gt;" . "Database connection failed: " . mysql_error() . "&lt;/p&gt;");
  
  // Put table names from database into variables.
  $agents = "agents";
  
  // Check if query was successful. If not print error message.
  $extractID=mysql_query("SELECT * FROM $agents") or die ("&lt;p&gt;" . "MySQL connection failed: " . mysql_error() . "&lt;/p&gt;");
  
  // If number in database is even use one email address - if odd use other email address
  while($row = mysql_fetch_array($extractID))
  {
      // echo $row['AgentNumber'];
      $number = $row['AgentNumber'];
      if ($number % 2 == 0) {
          // print "It's even when setting email address";
          $EmailTo = 'myemail1@myemail.com.au';
      } else {
          // print "It's odd when setting email address";
          $EmailTo = 'myemail2@myemail.com.au';
      }
  }
  
  //check if its an ajax request, exit if not
  if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
  
      $output = json_encode(array( //create JSON data
          'type'=&gt;'error', 
          'text' =&gt; 'Sorry Request must be Ajax POST'
      ));
      die($output); //exit script outputting json data
  } 
  
  //Sanitize input data using PHP filter_var().
  $first_name     = filter_var($_POST["first_name"], FILTER_SANITIZE_STRING);
  $last_name      = filter_var($_POST["last_name"], FILTER_SANITIZE_STRING);
  $phone_number   = filter_var($_POST["phone_number"], FILTER_SANITIZE_NUMBER_INT);
  $buyer_profile  = filter_var($_POST["buyer_profile"], FILTER_SANITIZE_STRING);
  $interested_in  = filter_var($_POST["interested_in"], FILTER_SANITIZE_STRING);
  $user_email     = filter_var($_POST["user_email"], FILTER_SANITIZE_EMAIL);
  $post_code      = filter_var($_POST["post_code"], FILTER_SANITIZE_NUMBER_INT);
  $suburb         = filter_var($_POST["suburb"], FILTER_SANITIZE_STRING);
  
  $first_name_flag = 0;
  // Loop thru first name and check for number, if so set flag.
  for($i=0;$i&lt;strlen($first_name);$i++){
      if(is_numeric($first_name[$i])){
          $first_name_flag = 1;
      }
   }
   $last_name_flag = 0;
  // Loop thru first name and check for number, if so set flag.
  for($i=0;$i&lt;strlen($last_name);$i++){
      if(is_numeric($last_name[$i])){
          $last_name_flag = 1;
      }
   }
  
  //additional php validation
  if($first_name_flag){ // check for letters and spaces only in name field
      $output = json_encode(array('type'=&gt;'error', 'text' =&gt; 'First Name as letters and spaces only!'));
      die($output);
  }
  if($last_name_flag){ // check for letters and spaces only in name field
      $output = json_encode(array('type'=&gt;'error', 'text' =&gt; 'Last Name as letters and spaces only!'));
      die($output);
  }
  if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $user_email)){ //email validation
      $output = json_encode(array('type'=&gt;'error', 'text' =&gt; 'Please enter a valid email!'));
      die($output);
  }
  
  //email body
  // $message_body = $message. "\r\n\r\n-" . $user_name . "\r\nEmail : " . $user_email . "\r\nPhone Number : " . $phone_number . "\r\nPostcode : " . $post_code;
  $message_body  = "&lt;html&gt;&lt;body style='font-family:Arial,sans-serif;'&gt;";
  $message_body .= "&lt;h2 style='color:#F20;'&gt;Request from MY website&lt;/h2&gt;\r\n";
  $message_body .= "&lt;p&gt;&lt;strong&gt;Name:&lt;/strong&gt; ".$first_name.' '.$last_name."&lt;/p&gt;\r\n";
  $message_body .= "&lt;p&gt;&lt;strong&gt;Phone:&lt;/strong&gt; ".$phone_number."&lt;/p&gt;\r\n";
  $message_body .= "&lt;p&gt;&lt;strong&gt;Buyer Profile:&lt;/strong&gt; ".$buyer_profile."&lt;/p&gt;\r\n";
  $message_body .= "&lt;p&gt;&lt;strong&gt;Interested In:&lt;/strong&gt; ".$interested_in."&lt;/p&gt;\r\n";
  $message_body .= "&lt;p&gt;&lt;strong&gt;Email from:&lt;/strong&gt; ".$user_email."&lt;/p&gt;\r\n";
  $message_body .= "&lt;p&gt;&lt;strong&gt;Postcode:&lt;/strong&gt; ".$post_code."&lt;/p&gt;\r\n";
  $message_body .= "&lt;p&gt;&lt;strong&gt;Suburb:&lt;/strong&gt; ".$suburb."&lt;/p&gt;\r\n";
  $message_body .= "&lt;/body&gt;&lt;/html&gt;";
  
  //proceed with PHP email.
  $subject  = "Register interest from Amara City Gardens website";
  $headers  = "From: " . strip_tags($user_email) . "\r\n";
  $headers .= "Reply-To: ". strip_tags($user_email) . "\r\n";
  $headers .= "MIME-Version: 1.0\r\n";
  $headers .= "Content-Type: text/html;charset=utf-8 \r\n";
  
  $send_mail = mail($EmailTo, $subject, $message_body, $headers);
  
  if(!$send_mail)
  {
      //If mail couldn't be sent output error. Check your PHP email configuration (if it ever happens)
      $output = json_encode(array('type'=&gt;'error', 'text' =&gt; 'Could not send mail! Please check your PHP mail configuration.'));
      die($output);
  }else{
  
      // This is to increase the number inside the database by one, 
      // so the next submit in php can check if the number is even or odd
  
      // Define variables used for connection to database.
      $server = "localhost"; 
      $username = "myusername";
      $password = "mypw";
      $db_name = "mydb";
  
      // Connect to server and select database
      mysql_connect($server, $username, $password) or die ("&lt;p&gt;" . "MySQL connection failed: " . mysql_error() . "&lt;/p&gt;");
      mysql_select_db($db_name) or die ("&lt;p&gt;" . "Database connection failed: " . mysql_error() . "&lt;/p&gt;");
  
      // Put table names from database into variables.
      $agents = "agents";
  
      // Check if query was successful. If not print error message.
      $extractID=mysql_query("SELECT * FROM $agents") or die ("&lt;p&gt;" . "MySQL connection failed: " . mysql_error() . "&lt;/p&gt;");
  
      // If number in database is even use one email address - if odd use other email address
      while($row = mysql_fetch_array($extractID))
      {
          // echo $row['AgentNumber'];
          $number = $row['AgentNumber'];
          if ($number % 2 == 0) {
              $number++;
              // Insert Check if query was successful. If not print error message.
              $insertNew=mysql_query("UPDATE $agents SET AgentNumber=$number WHERE AgentID=1") or die ("&lt;p&gt;" . "MySQL connection failed: " . mysql_error() . "&lt;/p&gt;");
          } else {
              $number++;
              // Insert Check if query was successful. If not print error message.
              $insertNew=mysql_query("UPDATE $agents SET AgentNumber=$number WHERE AgentID=1") or die ("&lt;p&gt;" . "MySQL connection failed: " . mysql_error() . "&lt;/p&gt;");
          }
      }
  
      $output = json_encode(array('type'=&gt;'message', 'text' =&gt; 'Hi '.$user_name . '.&lt;br /&gt;' .' Your enquiry has been submitted. Our sales team will be in contact shortly.'));
      die($output);
  }
  </code></pre>
  
  <p>}
  ?></p>
  
  <p>Any help is much appreciated.</p>