title: how to update the php variable using jquery variable
body: <p>Hi I am developing a shopping cart.The products ordered by a customer is shown to him. All the products and their details are stored in a <code>session</code> variable. He can change the quantity of each product, if he wants to.When he changes the quantity of a product,corresponding price changes.This I have done using <code>jquery</code>. Now I need to update the session variable,when he changes the quantity. And I have to display it also.</p>
  
  <p>Here is my code.</p>
  
  <pre><code>&lt;?php
   session_start();
   include('head.php');
  
  
   ?&gt;
   &lt;!DOCTYPE HTML&gt;
   &lt;head&gt;
   &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt;  
    &lt;script&gt;
     $(document).ready(function() {   
          $(".myclass").change(function(){
              var identifier = $(this).attr('id');
              var Qty = $(this).val();
              var Price = $("#price_"+identifier).val();//price value
              var Total =  Qty * Price;  
              $("#priceDisplay_"+identifier).html(Total);                 
              GrandTotal();
             });
           GrandTotal();      
            });
  
          function GrandTotal(){
          var GrandTotal=0;
          var cart=0;
           $(".myclass").each(function(){
               var identifier = $(this).attr('id');
               var Qty = $(this).val();    
               var Price = $("#price_"+identifier).val();//price value
               cart +=parseInt(Qty);
               var Total =  Qty * Price; 
  
               GrandTotal += Total;
               $("#priceDisplay_"+identifier).html(Total); 
  
             });
        $("#cart").html(cart);
        $("#GrandTotal").html(GrandTotal);
  
      }
  
    function RemoveCart(ob){
           if (confirm("Are you sure to Remove?"))
           {    
           var IdForRemove =ob.value;
  
           $.ajax({
               type: "POST",
               url: "RemoveCart.php",
               dataType:'json',
               data: { id: IdForRemove}
               })
               .done(function( data ) {
                   $("#GrandTotal").html(data.Grandtotal);                    
                   $("#cart").html(data.cart);
                   $("#"+IdForRemove).remove();
  
               });
  
           return false;
  
           }
       }
  
   &lt;/script&gt;
   &lt;/head&gt; 
   &lt;body&gt;
  
  
        &lt;?php
        if(empty($_SESSION['items'])){ ?&gt;
  &lt;center&gt;&lt;b&gt;&lt;font color="red"&gt;There are no products in your cart!!&lt;/font&gt;&lt;/b&gt;&lt;/center&gt;    
           &lt;?php  
         }
        else
  
           {
           ?&gt;
  
        &lt;b&gt;&lt;font color="#0000A0"&gt; Your Shopping Cart!!&lt;/font&gt;&lt;/b&gt;&lt;br&gt;&lt;br&gt;
      &lt;form name="formview" action="orderform.php" method="post"&gt;
     &lt;?php $count=0; 
         ?&gt;
  
  
       &lt;table  id="mytable" width="50%" cellpadding="1px" cellspacing="3px" border="1" bgcolor="#BDEDFF"&gt;
          &lt;tr&gt;  
          &lt;th&gt;Item&lt;/th&gt;
          &lt;th&gt;Price&lt;/th&gt;
          &lt;th&gt;Quantity&lt;/th&gt;
          &lt;th&gt;Subtotal&lt;/th&gt;
           &lt;th&gt;Remove&lt;/th&gt;
          &lt;/tr&gt; 
      &lt;?php  
      $cnt=0; 
     $CartR = $_SESSION['r'];
     foreach( $CartR as $key=&gt;$ar):
      $Identifier = 'qty_'.$cnt;  
  
       ?&gt;    &lt;tr id="&lt;?php echo $ar['Id']; ?&gt;"&gt;
  
          &lt;td align="center"&gt;&lt;?php echo $ar['Name']?&gt;&lt;/td&gt;
          &lt;td align="center"&gt;&lt;?php echo $ar['Price']?&gt;&lt;/td&gt;
         &lt;td align="center"&gt;
         &lt;select class="myclass" name="qty" id='&lt;?php echo $Identifier;?&gt;' &gt;
         &lt;?php for ($i=1; $i&lt;=100; $i++) {
                 $y="";
                 if( $i==$_SESSION['r'][$key]['Quantity']){
                  $y="selected";
                  }
                  echo "&lt;option ";
                  echo "value=\"$i\" ".$y."&gt;", $i, "&lt;/option&gt;\n";
  
  
              } ?&gt;
  
         &lt;/select&gt;
         &lt;/td&gt;
  
          &lt;?php $x=$x+$ar['Quantity']; ?&gt;
  
           &lt;td name="price"&gt;&lt;span id="priceDisplay_&lt;?php echo $Identifier;?&gt;"&gt;&lt;?php echo $ar['Total']; ?&gt;&lt;/span&gt;&lt;/td&gt;          
          &lt;input type='hidden' name='id' id="pid_&lt;?php echo $Identifier;?&gt;" value='&lt;?php echo $ar['Id']; ?&gt;'&gt;
          &lt;input type='hidden' name='price' id="price_&lt;?php echo $Identifier;?&gt;" value='&lt;?php echo $ar['Price'] ?&gt;' class="input"&gt;  
          &lt;td&gt;
          &lt;input type="checkbox" onclick="RemoveCart(this)" value="&lt;?php echo $ar['Id']; ?&gt;"&gt; 
  
        &lt;?php   $tt[]=$ar['Total']; ?&gt;
       &lt;/tr&gt;
     &lt;?php
     $cnt++;     
      endforeach;
       ?&gt;  &lt;/table&gt;
      &lt;br&gt;&lt;br&gt;
       &lt;table&gt;
           &lt;tr&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;b&gt;&lt;font color="B048B5"&gt;Grand Total :&lt;/font&gt;&lt;/b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span id="GrandTotal"&gt;&lt;/span&gt;&lt;/tr&gt;
        &lt;b&gt;&lt;!--&lt;font color="#F6358A"&gt;Your Cart:--&gt;&lt;/font&gt;&lt;/b&gt;&lt;div align="center" id="cart"&gt;&lt;/div&gt; 
       &lt;center&gt;  &lt;img src="upload/images.jpeg" width="100"&gt;&lt;/center&gt;
       &lt;/table&gt;
  
  
        &lt;!--&lt;table align="right"&gt;--&gt;
      &lt;?php foreach($tt as $t)
      {
          $count=$count+$t;
      }
  
     ?&gt;  
      &lt;br&gt;
      &lt;br&gt;
  
      &lt;!--&lt;b&gt;&lt;div id="cart"&gt;Your Cart:&lt;/div&gt;&lt;/b&gt; --&gt;  
  
        &lt;?php
         }       
             if(!empty($_SESSION['r']))
            {  ?&gt;
  
         &lt;input type="submit" name="checkout" value="CheckOut"&gt;
        &lt;?php } ?&gt;
         &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;    &lt;a href="ebazaar.php"&gt;&lt;b&gt;&lt;font  color="#7D0541"&gt;Back&lt;/font&gt;&lt;/b&gt;&lt;/a&gt;
  
  
          &lt;/form&gt;
           &lt;/body&gt;
  </code></pre>
  
  <p>Anyone please help me. The change I made using jquery should also change my php variables.</p>
  
  <p>This is my updated sessionupdate.php</p>
  
  <pre><code>    &lt;?php session_start();
        include('head.php');
  
         $qnty=$_GET['quantity'];
        $prce=$_GET['price1'];
          $_SESSION['r']=$_GET['id'];
         $pid=$_GET['pid'];
            foreach ($_SESSION['r'] as $key =&gt; $value) {
           if($key==$pid){ 
         $_SESSION['r'][$key]['Quantity']=  $qnty;
             $_SESSION['r'][$key]['Total']=  $prce*$qnty;
           }
          }
  </code></pre>
  
  <p>here pid is my product_id passed from ajax.Please help me</p>