title: Can't figure out why PHP not receiving POST data from $.ajax call
body: <p>It's not like I haven't done this same process before, but I can't figure out why my PHP script's POST data is empty. Here's what I've done/found:</p>
  
  <ol>
  <li><p>I've verified that the $.ajax call's "data" parameter has a value (alerts in the submitSearch function and in the success parameter show the correct value of the search variable).</p></li>
  <li><p>I know that the script is being "found" - no file not found messages in the js console in the browser.</p></li>
  <li><p>I'm not getting any db connection errors</p></li>
  <li><p>I also know that the PHP script is running because the alert in the $.ajax call's success parameter is displaying the $message value in the PHP script's else clause.</p></li>
  <li><p>The logging I have set up in the PHP script is displaying nothing for the POST data</p></li>
  </ol>
  
  <p>I'd greatly appreciate it if someone can take a look at this and hopefully point out what I'm missing.</p>
  
  <p>Here is all of the relevant code:</p>
  
  <hr>
  
  <p>Javascript (in a script tag within the HTML file)</p>
  
  <hr>
  
  <pre><code>$('input#btnSubmitSearch').click(function() {
  // Clear the text box in case an error was indicated previously
  $('input#txtSearch').css({'background-color' : ''});
  
  var search = $('input#txtSearch').val();
  
  if (search == '' || search.length != 5) {
      alert ('Not a valid entry!');
      $('input#txtSearch').css({'background-color' : '#FDC3C3'});
      return false;
  }
  else {
      submitSearch(search);
      return false;
  }
  });
  
  function submitSearch(search) {
  alert ('Sending ' + search + ' to the database.');
  
  $.ajax({
      type: 'POST',
      url: 'scripts/search.php',
      data: search,
      cache: false,
      success: function(response) {
          alert ('search is: ' + search + ', Response from PHP script: ' + response);
      },
      error: function(xhr) {
          var response = xhr.responseText;
          console.log(response);
          var statusMessage = xhr.status + ' ' + xhr.statusText;
          var message  = 'Query failed, php script returned this status: ';
          var message = message + statusMessage + ' response: ' + response;
          alert(message);
      }
  });
  }
  </code></pre>
  
  <hr>
  
  <p>PHP script (scripts/search.php)</p>
  
  <hr>
  
  <pre><code>&lt;?php
  require_once ('logging.php');
  $log = new Logging();
  
  $dbc = @mysqli_connect([connection stuff])
      OR die ('Could not connect to MySQL server: ' . mysqli_connect_error() );
  
  $log-&gt;lwrite('$_POST[\'search\']: ' . $_POST['search']);
  
  if (isset($_POST['search'])) {
  
      $search = $_POST['search'];
  
      $log-&gt;lwrite('$search: ' . $search);
  
      $querySearch= "SELECT id, value
                              FROM table
                              WHERE value LIKE '%" . $search . "%'";
  
      $log-&gt;lwrite('$querySearch: ' . $querySearch);
  
      $resultSearch = @mysqli_query($dbc, $querySearch);
  
      $numRowsSearch = mysqli_num_rows($resultSearch);
  
      $log-&gt;lwrite('rows returned: ' . $numRowsSearch);
  
      if ($numRowsSearch &gt; 0) {
          while ($rowSearch = mysqli_fetch_array($resultSearch, MYSQLI_ASSOC)) {
              echo 'Value found: ' . $rowSearch['value'];
          }
      } 
  }
  else {
      $errorMessage ='$_POST[\'search\'] doesn\'t have a value!'; 
      $log-&gt;lwrite($errorMessage);
      echo ($errorMessage);
  }
  </code></pre>