title: Does not allow same product more than a one-time CodeIgniter shopping cart
body: <p>I am using the CodeIgniter shopping cart and below is the code which displaying my all the details on the browser.</p>
  
  <p>(Just share the logic part)</p>
  
  <pre><code>&lt;?php
     foreach ($post as $row) {?&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;?php echo $i++;?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $row-&gt;name;?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $row-&gt;price;?&gt;&lt;/td&gt;
      &lt;td&gt;
        &lt;?php if($row-&gt;is_approved==1){?&gt;&lt;button type="button" name="renew" class="btn btn-success add_cart"&gt;Add to cart&lt;/button&gt;
        &lt;?php }else{?&gt;
        &lt;div class="activity_status"&gt;Not Approved&lt;/div&gt;
        &lt;?php };?&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;div id="primarycart_details"&gt;&lt;/div&gt;
    &lt;?php}?&gt;
  </code></pre>
  
  <p>I am getting the output on the browser</p>
  
  <pre><code>    Id | Name   | price  | Action
      1  | poimjh | 10     | Add to cart
      2  | asdasd | 100    | Add to cart
      3  | dgfdfw | 50     | Add to cart
      4  | qwewqe | 100    | Not Approved
     // and so on
  </code></pre>
  
  <p>Now My issue is, When I clicked on add to cart it's adding the product details in the cart and also I am changing the button status from <code>Add to cart</code> to <code>Remove</code>. Now When I refresh the page then my button again change from <code>Remove</code> to <code>Add to cart</code>. I don't want to add the same product more than one time.</p>
  
  <p><strong>Ajax</strong></p>
  
  <pre><code>    $(document).ready(function(){
    $(document).on('click', '.add_cart', function() {
    var product_name = $(this).closest('tr').find('.productname').text();
    var product_id = $(this).closest('tr').find('.productid').val();
    var product_price = $(this).closest('tr').find('.calActivitylPrice').text();
        var quantity =1;
         $.ajax({
          url:"&lt;?php echo base_url(); ?&gt;Member_controller/addToCart",
          method:"POST",
          data:{product_id:product_id, product_name:product_name, product_price:product_price,quantity:quantity},
          success:function(data)
          {
              var obj = JSON.parse(data);
            //alert(data);
           $('#changeToRemove').html('&lt;button type="button" name="remove" class="btn btn-danger btn-xs remove_inventory" id="'+obj.removebtn+'"&gt;Remove&lt;/button&gt;')
           $('#primarycart_details').html(obj.subtotal);
          }
         });
       });
      });
  </code></pre>
  
  <p><strong>Remove code</strong></p>
  
  <pre><code>$(document).on('click', '.remove_inventory', function(){
    var row_id = $(this).attr("id");
    //alert(row_id);
    if(confirm("Are you sure you want to remove this?"))
    {
     $.ajax({
      url:"&lt;?php echo base_url(); ?&gt;Member_controller/Removecart",
      method:"POST",
      data:{row_id:row_id},
      success:function(data)
      {
       alert("Product removed from Cart");
      }
     });
    }
    else
    {
     return false;
    }
   });
  </code></pre>
  
  <p><strong>Remove from a cart in controller</strong></p>
  
  <pre><code>public function Removecart(){
   $row_id = $_POST["row_id"];
   //echo $row_id;
    $data = array(
     'rowid'  =&gt; $row_id,
     'qty'  =&gt; 0
    );
    //print_r($data);
    $this-&gt;cart-&gt;update($data);
    echo $this-&gt;viewCart();
  
  }
  </code></pre>
  
  <p><strong>Add to cart code in controller</strong></p>
  
  <pre><code>public function addToCart(){
    $data = array(
     "id"  =&gt; $_POST["product_id"],
     "name"  =&gt; $_POST["product_name"],
      "qty"  =&gt; $_POST["quantity"],
     "price"  =&gt; $_POST["product_price"]
    );
    //print_r($data);
    $this-&gt;cart-&gt;insert($data); //return rowid 
    //echo $this-&gt;viewCart();
  }
  </code></pre>
  
  <p>Can anyone help me out on this issue?</p>