title: POST 500 Internal Server Error -- PHP
body: <h2>A strange problem that is making me puzzled</h2>
  
  <p>this code was working perfectly at localhost</p>
  
  <p>And after uploading to server i found this : 
  Failed to load resource: the server responded with a status of 500 (Internal Server Error)</p>
  
  <p>and some other times it shows : POST $link 500 (Internal Server Error)</p>
  
  <p>Wordpress !</p>
  
  <p><strong>AJAX Code:</strong></p>
  
  <pre><code>function fetch_select(val) {
      $.ajax({
          type: 'post',
          url: 'test2.php',
          data: {
              get_option:val
          },
          success: function (response) {
              $('.restaurnat').html(response);
          }
      });
  }
  </code></pre>
  
  <p><strong>PHP Code:</strong></p>
  
  <pre><code>&lt;?php
  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
      if (isset($_POST['get_option'])) {
          if (!empty($_POST['get_option']) &amp;&amp; $_POST['get_option'] != 0) {
              global $wpdb;
              $rests = $wpdb-&gt;get_results("SELECT * FROM Cities WHERE ID = $_POST['get_option']", ARRAY_A);
              if (!empty($rests)) {
                  foreach ($rests as $rest) {
                      echo "&lt;option value='" . $rest['ID'] . "'&gt;" . $rest['res'] . "&lt;/option&gt;";
                  }
              }
          } else {
              echo "&lt;option value=''&gt; --- Choose Country or City First --- &lt;/option&gt;";
          }
      }
  }
  ?&gt;
  </code></pre>
  
  <p><strong>HTML Code:</strong></p>
  
  <pre><code>&lt;div class='container'&gt;
      &lt;h1 class='text-center'&gt;Choosing requests&lt;/h1&gt;
      &lt;form class='text-center form-horizontal' style='padding:10px;max-width:400px;margin:auto;' action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method='POST'&gt;
          &lt;h1 class="text-center" style='font-size:3.9em;margin:40px 0;font-weight:bold;'&gt;Choose City or Country&lt;/h1&gt;
          &lt;select name='city' onchange='fetch_select(this.value)'&gt;
              &lt;option value=''&gt;--- Choosing City or Country ---&lt;/option&gt;
              &lt;?php
                  global $wpdb;              
                  $q = $wpdb-&gt;get_results("SELECT City_Name, ID FROM Cities ORDER BY ID ASC", ARRAY_A);
                  if (!empty($q)) {
                      foreach ($q as $city) {?&gt;
                          &lt;option value="&lt;?php echo $city['ID']; ?&gt;"&gt;&lt;?php echo $city['City_Name']; ?&gt;&lt;/option&gt; 
                      &lt;?php 
                      }
                  } else {
                      echo "&lt;div class='container'&gt;&lt;div class='alert alert-warning'&gt;&lt;p class='lead'&gt;There is no city or Country at the database&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;";
                  }
              ?&gt;
          &lt;/select&gt;
          &lt;br /&gt;
          &lt;h1 class="text-center" style='font-size:3.9em;margin:40px 0;font-weight:bold;'&gt;Choose restaurant&lt;/h1&gt;
          &lt;select name='restaurant' class='restaurnat'&gt;
              &lt;option value=''&gt;--- Choose Country or City first ---&lt;/option&gt;
          &lt;/select&gt;
          &lt;input type='submit' value='Order now' class='btn btn-lg btn-primary' style='margin:10px;'/&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>