title: AJAX getting data from selected dropdown and giving result PHP
body: <p><a href="https://i.stack.imgur.com/Ugk01.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ugk01.png" alt="enter image description here"></a></p>
  
  <p>I need to get two data from my both dropdowns.
  First dropdown gets fabricID  and the second gets sizeID.
  And then ajax sends the selected data to calculates.php</p>
  
  <p>I used two functions to get each dropdown data inside of one <code>$(document).ready(function(){...</code></p>
  
  <pre><code>$(document).ready(function(){
  
      $('.fabric').on('change',function(){
          var fabricID = $(this).val();
          console.log("fabric id_price is " + fabricID); //debugging
          if(fabricID){
             $.ajax({
                  type:'POST',
                  url:'calculates.php',
                  dataType: 'json',
                  data: {
                  fabric_id: fabricID
                  },
  
                  success:function(html){                                                          
                      //closing tags 
                      //dont need nothing here because i need 
                      //just to get the value from both together
  
      });
  
      $('.size').on('change',function(){
          var sizeID = $(this).val();
          if(sizeID){
              $.ajax({
                  type:'POST',
                  url:'calculates.php',
                  dataType: 'json',
                  data: {
                  size_id: sizeID
                  },
  
                  success:function(html){
                      $('.icms').html(html); // i need to get result here 
                      based on the result from calculates.php
                 //closing tags
  </code></pre>
  
  <p>Is this right?
  Did I build the jQuery script the right way?</p>
  
  <p>Because its not working.
  Look to my tables:
  table:almofads is where is stored my fabrics names
  <a href="https://i.stack.imgur.com/TljmS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TljmS.png" alt="enter image description here"></a></p>
  
  <p>and i will get the id_price from the dropdown fabrics and send the id_price to
  table:valores_almofadas where price_id has to be equal to the first table.</p>
  
  <p><a href="https://i.stack.imgur.com/IRA6z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IRA6z.png" alt="enter image description here"></a></p>
  
  <p>So when I select fabricID and sizeID, I will get the result from here...calculates.php</p>
  
  <pre><code> &lt;?php header('Content-Type: application/json');
   include_once '../incluedes/conn_cms.php'; //session started here
  
   if(isset($_GET["size_id"],$_GET["id_price"])){
      $size_id=$_GET["size_id"] ;
      $id_price=$_GET["id_price"] ;
  
  
   $query3 =" SELECT * FROM valores_almofadas 
              WHERE size='$size_id' 
              AND price_id ='$id_price'";
  
     $result = mysqli_query($conn,$query3);
     while($rows = mysqli_fetch_assoc($result)){
  
          if($_SESSION['estado'] == 'SP'){
             $ICMS = $rows['icms_7'];
             }else{
             $ICMS = $rows['icms_12'];
             }
             $_SESSION['icms']=$ICMS;
  
          } echo json_encode($_SESSION['icms']);
  
  } 
  ?&gt;
  </code></pre>
  
  <p>so the result will be displayed here in cart.php in <code>$_SESSION['icms']</code></p>
  
  <pre><code>function cart(){
      global $conn;
  
      $fabric_options = '&lt;option&gt;Select fabric&lt;/option&gt;';
      $query2 = "SELECT * FROM almofadas";
      $result = mysqli_query($conn,$query2);
      while($rows = mysqli_fetch_assoc($result)){
       $tecido=$rows['tecido'];
       $id_price=$rows['id_price'];
       //sizes for size dropdown
       $t50='50';
       $t45='45';
       $fabric_options .= '&lt;option value="'.$id_price.'"&gt;'.$tecido.'&lt;/option&gt;';
      }
  
   foreach ($_SESSION as $name =&gt; $value) {
       if($value &gt; 0){
       if(substr($name, 0, 8 ) == "product_"){
       $length = strlen($name) -8;
       $item_id = substr($name,8 , $length);
       $query = "SELECT * 
                 FROM gallery2 
                 WHERE gallery2.id =".escape_string($item_id). "";
                 $run_item = mysqli_query($conn,$query);
    while($rows = mysqli_fetch_assoc($run_item)){ 
       $vari   = $rows['variante'];
       $num    = $rows['title'];
       $id     = $rows['id'];
  
   $btn_add ='&lt;button type="button" class="btn btn-success actions plus" data-action="plus" product_id="'.$id.'"&gt;&lt;i class="fa fa-plus fa-lg" aria-hidden="true" add_btn&gt;&lt;/i&gt;&lt;/button&gt;';
  
   $btn_remove ='&lt;button type="button" class="btn btn-warning actions less" data-action="remove" product_id="'.$id.'"&gt;&lt;i class="fa fa-minus fa-lg" aria-hidden="true" remove_btn&gt;&lt;/i&gt;&lt;/button&gt;';
  
   $btn_delete ='&lt;button type="button" class="btn btn-default actions" data-action="delete" product_id="'.$id.'" onclick="deleteRow(this)"&gt;&lt;i class="fa fa-times fa-lg" aria-hidden="true"&gt;&lt;/i&gt;&lt;/button&gt;';
      if($rows['variante'] &lt; 1){
      $vari="";
      }else{
      $vari = "-".$rows['variante'];
      }
  
      $product = '
      &lt;tr&gt;
         &lt;td style="width:100px; "&gt;&lt;img src="../'.$rows['image'].'" style="width:90%;border: 1px solid black;"&gt;&lt;/td&gt;
         &lt;td&gt;'.$num.''.$vari.'&lt;/td&gt;
         &lt;td style="width:15%;"&gt;
            &lt;select name="fabric" class="fabric select form-control selectpicker" required=""  &gt;
          '. $fabric_options . '  
            &lt;/select&gt;
         &lt;/td&gt;
         &lt;td&gt;
            &lt;select  id="" class="select size form-control selectpicker" required style="width:80%;"  &gt;
            &lt;option value="'.$t50.'"&gt;50x'.$t50.'&lt;/option&gt;
            &lt;option value="'.$t45.'"&gt;45x'.$t45.'&lt;/option&gt;
            &lt;/select&gt;
         &lt;/td&gt;
         &lt;td class="product'.$id.'"&gt;'.$value.'&lt;/td&gt;//quantity of the product
         &lt;td class="icms'.$id.'"&gt;R$:'.$_SESSION['icms'] .'&lt;/td&gt; // cost of product
         &lt;td class="total'.$id.'"&gt;'.$value * $_SESSION['icms'] .' &lt;/td&gt; total of product (sub.total)
         &lt;td&gt; 
         '.$btn_add.' '.$btn_remove.' '.$btn_delete.'//buttons
         &lt;/td&gt;
       &lt;/tr&gt;';
             echo $product;  
  
          } 
        } 
      }
    }   
  }
  </code></pre>
  
  <p>and for last my buttons functions in cart_functions.php</p>
  
  <pre><code>header('Content-Type: application/json');
  session_start();
  
  if (isset($_GET['action'])) {
    $action = $_GET['action'];
    $prod   = $_GET['prod_id'];
    $prodname = 'product_'.$prod;
    $result;
  
    switch ($action) {
      case 'add':
          $result = add_prod($prod, $prodname);
      break;
      case 'plus':
          $result = plus_prod($prod, $prodname);
      break;
      case 'remove':
          $result = remove_prod($prod, $prodname);
      break;
      case 'delete':
          $result = delete_prod($prod, $prodname);
      break;
      default:
          $result = ['result'=&gt;'error'];
      break;
    }
  }
  
  echo json_encode($result);
  
  function add_prod($prod, $prodname){
    //sua função para add
   $_SESSION[$prodname] = 1;
   return ['result'=&gt;'success'];
  }
  
  function plus_prod($prod, $prodname){
    $_SESSION[$prodname]++;
    return ['result'=&gt;'success', 'val'=&gt;$_SESSION[$prodname]];
  }
  
  function remove_prod($prod, $prodname){
    //sua função para remove
    $_SESSION[$prodname]--;
    return ['result'=&gt;'success', 'val'=&gt;$_SESSION[$prodname]];
  }
  
  function delete_prod($prod, $prodname){
    //sua função para delete
    $_SESSION[$prodname] = null;
    return ['result'=&gt;'success'];
  }
  </code></pre>