title: Undefined variable $id everytime I use $_POST method
body: <p>I'm using post method to get the id but everytime tells me Undefined variable $id here is my code:</p>
  <pre><code>&lt;?php    
      require 'DBConnection.php';
      $code='';
      if(isset($_POST[&quot;ID&quot;])){
          if($_POST([&quot;ID&quot;]) != ''){
              $id = $_POST['ID'];
              $get_c = $pdo-&gt;prepare(&quot;SELECT * FROM all_menu WHERE `ID` = '&quot;.$id.&quot;'&quot;);
              $get_c-&gt;execute(); 
              while ($row = $get_c-&gt;fetch()) {
                  $code .= $row['item_code'];
              }
              echo $code;
          }
      }
  </code></pre>
  <p>Edit: I'm using this code to select from dropdown options to get the ID of the value in dropdown
  for example I have three options in my select dropdown let's say the first one is &quot;Pepsi&quot; when I select &quot;Pepsi&quot; I need to put its ID in an input I'm using PHP and Ajax in this code.</p>
  <p>Here is my Ajax code:</p>
  <pre><code>&lt;script&gt;
    $(document).ready(function(){
      $('#itemname').change(function(){
        var code = $(this).val();  
         $.ajax({
            type: 'POST',
            url: 'pages/GetCode.php',
            data:{code:code},
            success: function(data){
              document.getElementById(&quot;itemcode&quot;).value = data;
            },
            error: function (jqXHR, textStatus, errorThrown){ 
              alert(errorThrown);
            }
         });
      });
    });
  &lt;/script&gt;
  </code></pre>