title: Passing variable from Ajax to Php
body: <p>I've looked at all the previous examples but still no dice, and I have a basic php question.</p>
  
  <p>The example is <a href="http://whichchart.com/" rel="nofollow noreferrer">here</a>. I want to be able to click on one table and have the options appear like below:</p>
  
  <p><img src="https://i.stack.imgur.com/eAoL6.png" alt="Example"></p>
  
  <p>Explicitly declaring the table name in this code works:</p>
  
  <pre><code>if($_GET['action'] == 'getOptions'){
          $category = $_GET['category'];
          $query = "SELECT `COLUMN_NAME` 
                      FROM `INFORMATION_SCHEMA`.`COLUMNS` 
                      WHERE `TABLE_SCHEMA`='headfirstjson' AND 
                      **`TABLE_NAME`='AmericanOilProduction'**";
  
          $result = db_connection($query);
          //echo $result;
          $Options = array();
  
          while ($row = mysql_fetch_array($result)) {                
                  $Options[] = $row;
          }
          echo json_encode(array("Options" =&gt; $Options));
          exit;
  }
  </code></pre>
  
  <p>This combination of passing in the variable by AJAX does not:</p>
  
  <p>AJAX:</p>
  
  <pre><code>function getOptions(category){
  var category = category.value
  $.ajax({
      url: "getData.php?action=getOptions",
      type: "GET",
      dataType:"json",
      data: {category:category},
      success: function(json){
          $.each(json.Options,function(){
          var option = "&lt;option&gt;"+this.COLUMN_NAME+"&lt;/option&gt;"
          $('#options').append(option)
      });  
      }
  });
  }
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code>if($_GET['action'] == 'getOptions'){
          **$category = $_GET['category']**;
          $query = "SELECT `COLUMN_NAME` 
                      FROM `INFORMATION_SCHEMA`.`COLUMNS` 
                      WHERE `TABLE_SCHEMA`='headfirstjson' AND 
                      `TABLE_NAME`='**.$category.**'";
  
          $result = db_connection($query);
          //echo $result;
          $Options = array();
  
          while ($row = mysql_fetch_array($result)) {                
                  $Options[] = $row;
          }
          echo json_encode(array("Options" =&gt; $Options));
          exit;
      }
  </code></pre>
  
  <p>It would be great if someone could help me out! Thanks.</p>