title: AJAX call error 500 (Internal Server Error)
body: <p>I have a page that, upon loading, fills 3 drop down menus for uses to select from.  On my localhost, this works fine, but on my live server I get the error in Developer Tools "POST (my site's name) 500 (Internal Server Error) jquery.js:8630.</p>
  
  <p>Here is the jquery:</p>
  
  <pre><code>$(function() {
      //after load, populate lists
      Update_List_ProcedureAreas_Schedule();
      Update_List_Patients_Cancel();
      Update_List_Cancel_Reasons();
  });
  </code></pre>
  
  <p>Here's one of the functions, but the other two are nearly identical, but all 3 fail.  I send to a generic functions php file the function that I want to run, and if there are any parameters with the function as well.  Maybe be a bit weird, but it helps me organize my code:</p>
  
  <pre><code>function Update_List_Patients_Cancel() {
      $.ajax({
          url: 'php/functions.php',
          type: 'POST',
          dataType: 'json',
          cache: false,
          data: {Function_ID: 'pull_patient_list_cancel'},
          success: function(data){
              var dropDown = document.getElementById("selectedpatient_cancel");
              dropDown.options.length=0;
              dropDown[dropDown.length] = new Option('', '')
              for (i = 0; i &lt; data.length; i++) {
                  dropDown[dropDown.length] = new Option(data[i].Patient_Name, data[i].Patient_UID)
              }
          },
          error: function() {
  
          }
      });
  }
  </code></pre>
  
  <p>Here is the PHP in 'php/functions.php' which takes the Function_ID and then uses a switch to verify the input and then call the function with any appropriate variables:</p>
  
  <pre><code>&lt;?php
      session_start();
      //Make sure a funciton was sent
      if(isset($_POST['Function_ID']) == true) {$tempFunction = $_POST['Function_ID'];}
      else {echo "No fuction selected";}
  
      //switch to functions
      switch($tempFunction) {
          case 'pull_patient_list_cancel':
              pull_patient_list_cancel();
              break;
      }
  
  
  //Pull patient list for cancel drop down
  function pull_patient_list_cancel() {
      require $_SESSION['db_connect'];  //code to connect to the database, which is successful, btw
  
      $returnArray = array();
  
      $sql = "
          SELECT Patient_UID, Patient_Name
          FROM tbl_patients
          WHERE Active = 1
          ";
  
      if($result = $conn-&gt;query($sql)) {
          $conn-&gt;close();
          foreach($result-&gt;fetch_all(MYSQLI_ASSOC) as $row) {
              $returnArray[] = $row;
          }
          echo json_encode($returnArray);
      } else {
          $conn-&gt;close();
          echo "Failed - pull patient lists cancel";
      }
  }
  </code></pre>
  
  <p>It looks like for some reason, I'm not able to execute in the foreach loop.  I've put in bogus echos to see where the function stops running, and it won't output any echo within the for each loop or after it, but it will up until that loop starts.  I've check the response log in Development Tools and see the bogus echos coming through until the foreach loop, and then nothing.</p>
  
  <p>Any ideas?</p>
  
  <p>------------Solution-----------------</p>
  
  <p>The problem was that I had mysqlnd installed on my localhost xampp setup, but it did not install on my digitalocean lampp server that I set up today.  So that made the fetch_all(MYSQLI) not work. However, I could stick with the mysql installation and use fetch_assoc() and it worked fine.</p>
  
  <p>But, I ended up installing mysqlnd on my digitalocean droplet by using:</p>
  
  <p>apt-get install php5-mysqlnd</p>
  
  <p>and then restarting the server with</p>
  
  <p>service apache2 restart</p>
  
  <p>and now all of my fetch_all(MYSQLI) functions work. Thanks everyone for your help.</p>