Shopping cart with json

Shopping cart with json

I have been pulling out my hair trying to find a solution for this particular problem .

I have built a shopping cart .

Once a users clicks on adds to cart the session is stored in a multidimensional array .

Everything works perfectly , my problem lies when I try to submit the data via json (I am submitting via json to prevent the page from refreshing).

Please view my code below

  1. <a href="cart.php?add=2&rid=2&db=user" class="default"><img src="add_to_cart.png"></a>

Here is the html code

  1. // This is te javascript code
     $(".default").click(function () {
        return false;
         $.ajax({
                     type:'GET',
                     url:  $('.default').attr('href')  ,
                     success:function(data) {
                        }         
                 });
    });









And this is my php code

  1. if(isset($_GET['add']))
     {
            $rid = $_GET['rid'];
            $db = $_GET['db'];
               
            if($_SESSION['cart_'.$_GET['add']]['value'] >= '1')
                {
                    echo $_SESSION['cart_'.$_GET['add']]['value']++ ;
               
                   
                   
                }
                else if ($_SESSION['cart_'.$_GET['add']] = array('rid'=>$rid,'db'=>$db,'value'=> '0'))
                {
                    $_SESSION['cart_'.$_GET['add']] = array('rid'=>$rid,'db'=>$db,'value'=> '1');
                   

                   
                }

     }




















The logic behind my thinking is when a user selects one product value will be incremented , when the user clicks on another value will be added .

The problem is using json value is only incremented on one product , even if you select another product with a different id .

I hope that all makes sense .

Thanks again.