I have two dropdowns where ajax gets the value from it and send to my page calculates.php and then i will get a result based on both dropdown selection. But its not working well. The problem is that im getting a error that is saying

Notice: Undefined index: icms in C:\xampp\htdocs\system\clientes\gallery\cart.php on line 159

Notice: Undefined index: icms in C:\xampp\htdocs\system\clientes\gallery\cart.php on line 160

icms is a variable that holds the $_SESSION['icms']. When i get the result i must store in session and get data from data base. I dont know why i am getting this. And my values are not returning.

my script

$(document).ready(function(e){
  e.preventDefault();
    $('.fabric').on('change',function(e){
        var fabricID = $(this).val();
        console.log("fabric id_price is " + fabricID); //debugging
        if(fabricID){
           $.ajax({
                type:'GET',
                url:'calculates.php',
                data:'id_price='+fabricID,
                success:function(html){                                                          

                  // do nothing cuz i just need to combine with script bellow 
               //some closing tags

    $('.size').on('change',function(e){
      e.preventDefault();
        var sizeID = $(this).val();
        if(sizeID){
            $.ajax({
                type:'GET',
                url:'calculates.php',
                dataType: 'json',
                data:'size_id='+sizeID,

                success:function(html){
                  $(".icms" + id).text(data.val);
              //some closing tags

this is where i get my dropdown data and search database... calculates.php

// this is calculates.php
header('Content-Type: application/json');
include_once '../incluedes/conn_cms.php'; 

if(isset($_GET["size_id"],$_GET["id_price"])){
    $the_size=$_GET["size_id"] ;
    $the_id_price=$_GET["id_price"] ;

 $query3 = "SELECT * FROM valores_almofadas 
            WHERE size='$the_size' 
            AND   price_id ='$the_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 $_SESSION['icms'];

}

and here where i am supouse to receive data from the result. this below is my cart.php script

$value holds quantity and the $id holds the product row id.

159 <td class="icms'.$id.'">R$:'.$_SESSION['icms'] .'</td>

160 <td class="total'.$id.'">'.$value * $_SESSION['icms'] .' </td>

well... if you are using sessions, where is your session start? It should always be before headers are set. Other than that, you are simply replacing the one time super-global $_SESSION and inline declaring it an assoc array.

Other than that, it doesn't look like anything else is out of the ordinary :-/ This does look like a snippet from a bigger page structure, though.. :-/

Are you sure you are getting data from the database? What happens if you do a var_dump($_SESSION) and var_dump($rows) ?

My sessions starts on my conn_cms.php.
I made my jquery code based on this tutorial.

Ok, what about adding the var_dumps on the variables?

i used in calculation.php and didnt get no data from the var_dump because the values must be set, so i thing the problem is my jquery/ajax.
But i not good with ajax,dont know what i am missing.

have you tried var_dump ($_GET)?

Also, it seems you are only sending id_price, but your isset() looks for id_price and size_id, which means you need to add that along with id_price...

data:'id_price='+fabricID + '&size_id='+sizeID, //or something like this...

In the future, you may want to consider having your HTML/GET/POST variable names be the same as the column names, as this will prevent confusion as to what you are sending and expecting. id_price='fabricID' seems awfully odd.. why not just 'fabricID=' + fabricID?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.