title: codeigniter update quantity not working
body: <p>quantity not update only If I add an item with the exact same options more than once to my cart, it replaces instead of increasing the qty of the existing item
  This is cart view code</p>
  
  <pre><code>`&lt;table class="table table-bordered table-hover"&gt;
  &lt;thead &gt;&lt;!-- Table head --&gt;
  &lt;tr&gt;
      &lt;th class="active"&gt;Sl&lt;/th&gt;
      &lt;th class="active col-sm-4"&gt;Product&lt;/th&gt;
      &lt;th class="active col-sm-2"&gt;Real Price&lt;/th&gt;
      &lt;th class="active "&gt;Qty&lt;/th&gt;
      &lt;th class="active "&gt;Disc Price&lt;/th&gt;
      &lt;th class="active"&gt;Total&lt;/th&gt;
      &lt;th class="active"&gt;Action&lt;/th&gt;
  
  &lt;/tr&gt;
  &lt;/thead&gt;&lt;!-- / Table head --&gt;
  &lt;tbody&gt;&lt;!-- / Table body --&gt;
  &lt;?php $cart = $this-&gt;cart-&gt;contents() ;
  
  ?&gt;
  &lt;?php $counter =1 ; ?&gt;
  &lt;?php if (!empty($cart)): foreach ($cart as $item) : ?&gt;
  
      &lt;tr class="custom-tr"&gt;
          &lt;td class="vertical-td"&gt;
              &lt;?php echo  $counter ?&gt;
          &lt;/td&gt;
          &lt;td class="vertical-td"&gt;&lt;?php echo $item['name'] ?&gt;&lt;/td&gt;
          &lt;td class="vertical-td"&gt;&lt;?php echo $item['pkprice'] ?&gt;&lt;/td&gt;
          &lt;td class="vertical-td"&gt;
  
              &lt;input  type="text" name="qty" style="width: 50px" value="&lt;?php echo $item['qty'] ?&gt;" onblur ="order(this);" id="&lt;?php echo 'qty'.$item['rowid'] ?&gt;" class="form-control"&gt;
  
          &lt;/td&gt;
          &lt;td&gt;
  
  
              &lt;div class="input-group"&gt;
                      &lt;span class="input-group-addon"&gt;
                        &lt;input type="checkbox" id="&lt;?php echo 'opt'.$item['rowid'] ?&gt;" onclick="return price_checkbox(this)" name="custom_price"
                               &lt;?php echo $item['price_option'] == 'custom_price' ? 'checked':'' ?&gt;
                               data-placement="top" data-toggle="tooltip" data-original-title="Custom Price"&gt;
                      &lt;/span&gt;
                  &lt;input  type="text" name="price" value="&lt;?php echo $item['price'] ?&gt;"  onblur ="order(this);" id="&lt;?php echo 'pri'.$item['rowid'] ?&gt;" class="form-control"
                          &lt;?php echo $item['price_option'] == 'custom_price' ? '':'disabled' ?&gt; &gt;
              &lt;/div&gt;
  
  
              &lt;input type="hidden" name="product_code" value="&lt;?php echo $item['id']  ?&gt;" id="&lt;?php echo 'code'.$item['rowid'] ?&gt;"&gt;
          &lt;/td&gt;
          &lt;td class="vertical-td"&gt;&lt;?php echo number_format($item['subtotal'], 2, '.', ',')  ?&gt;&lt;/td&gt;
  
          &lt;td class="vertical-td"&gt;
              &lt;?php echo btn_delete('admin/order/delete_cart_item/' . $item['rowid']); ?&gt;
          &lt;/td&gt;
  
      &lt;/tr&gt;
  
  
      &lt;?php
      $counter++;
  endforeach;
      ?&gt;&lt;!--get all sub category if not this empty--&gt;
  
  
  
  
  
  &lt;?php else : ?&gt; &lt;!--get error message if this empty--&gt;
      &lt;td colspan="6"&gt;
          &lt;strong&gt;There is no record for display&lt;/strong&gt;
      &lt;/td&gt;&lt;!--/ get error message if this empty--&gt;
  &lt;?php endif; ?&gt;
  &lt;/tbody&gt;&lt;!-- / Table body --&gt;
  </code></pre>
  
  <p> `</p>
  
  <p>This is Controller Code</p>
  
  <pre><code>public function add_cart_item_by_barcode(){
  
      $product_code = $this-&gt;input-&gt;post('barcode', true);
      $result = $this-&gt;order_model-&gt;validate_add_cart_item($product_code);
  
  
  
      if($result){
  
  
  
  
  
          $price = $this-&gt;check_product_rate($result-&gt;product_id, $qty=1);
  
          //product tax check
          $tax = $this-&gt;product_tax_calculate($result-&gt;tax_id, $qty=1, $price);
  
          $data = array(
              'id' =&gt; $result-&gt;product_code,
              'qty' =&gt; 1,
              'price' =&gt; $price,
              'buying_price' =&gt; $result-&gt;buying_price,
              'name' =&gt; $result-&gt;product_name,
              'pkprice' =&gt; $result-&gt;p_price,
              'tax' =&gt; $tax,
              'price_option' =&gt; 'general'
          );
          $this-&gt;cart-&gt;update($data);
          $this-&gt;session-&gt;set_flashdata('cart_msg', 'add');
      }
  
      redirect('admin/order/new_order/'.$flag ='add');
  }
  
  public function check_product_rate($product_id=null, $qty=null)
  {
      //tier Price check
      $tire_price = $this-&gt;order_model-&gt;get_tire_price($product_id, $qty);
  
      if($tire_price)
      {
          return $price = $tire_price-&gt;tier_price ;
      }
  
      //special offer check
      $this-&gt;tbl_special_offer('special_offer_id');
      $offer_price = $this-&gt;global_model-&gt;get_by(array("product_id"=&gt;$product_id), true);
  
      if(!empty($offer_price)) {
          $today = strtotime(date('Y-m-d'));
          $start_date = strtotime($offer_price-&gt;start_date);
          $end_date = strtotime($offer_price-&gt;end_date);
          if (($today &gt;= $start_date) &amp;&amp; ($today &lt;= $end_date)) {
              return $price = $offer_price-&gt;offer_price;
          }
      }
  
      //return regular rate
      $this-&gt;tbl_product_price('product_price_id');
      $general_price = $this-&gt;global_model-&gt;get_by(array("product_id"=&gt;$product_id), true);
      return $product_price = $general_price-&gt;selling_price;
  
  }
  
  /*** Product tax calculation ***/
  public function product_tax_calculate($tax_id, $qty ,$price)
  {
      $this-&gt;tbl_tax('tax_id');
      $tax = $this-&gt;global_model-&gt;get_by(array('tax_id'=&gt;$tax_id), true);
  
      //1 = tax in %
      //2 = Fixed tax Rate
  
      if($tax){
          if($tax-&gt;tax_type == 1)
          {
              $subtotal = $price * $qty;
              $product_tax = $tax-&gt;tax_rate * ($subtotal / 100);
  
              //return $result = round($product_tax, 2);
              return $result = $product_tax;
  
          }else
          {
  
              //$product_tax = $tax-&gt;tax_rate * $qty;
              $product_tax = $tax-&gt;tax_rate * $qty;
              return $result = $product_tax;
  
          }
      }
  }
  
  /*** Update Product Cart ***/
  public function update_cart_item()
  {
      $rowid = $this-&gt;input-&gt;post('rowid');
      $qty = $this-&gt;input-&gt;post('qty');
      $product_price = $this-&gt;input-&gt;post('price');
      $product_code = $this-&gt;input-&gt;post('product_code');
      $custom_price = $this-&gt;input-&gt;post('custom_price');
  
  
      if($qty !=0 )
      {
          //tbl product
          $this-&gt;tbl_product('product_id');
          $result = $this-&gt;global_model-&gt;get_by(array('product_code'=&gt; $product_code ), true);
  
          //product Inventory Check
          $this-&gt;tbl_inventory('inventory_id');
          $product_inventory = $this-&gt;global_model-&gt;get_by(array('product_id'=&gt; $result-&gt;product_id ), true);
  
          if($qty &gt; $product_inventory-&gt;product_quantity)
          {
              $type = 'error';
              $message = 'Sorry! This product has not enough stock.';
              set_message($type, $message);
              echo 'false';
              return;
          }
  
  
          if($custom_price == "on")
          {
                 $price = $product_price;
                 $price_option = 'custom_price';
  
          }
          else
          {
              //product price check
              $price = $this-&gt;check_product_rate($result-&gt;product_id, $qty);
              $price_option = 'general';
          }
  
  
          //product tax check
          $tax = $this-&gt;product_tax_calculate($result-&gt;tax_id, $qty, $price);
  
  
  
          $data = array(
              'rowid' =&gt; $rowid,
              'qty' =&gt; $qty,
              'price' =&gt; $price,
              'tax'   =&gt; $tax,
              'price_option' =&gt; $price_option
  
          );
      }else
      {
          $data = array(
              'rowid' =&gt; $rowid,
              'qty' =&gt; $qty,
          );
      }
  
      $this-&gt;cart-&gt;update($data);
  
      if($this-&gt;input-&gt;post('ajax') != '1'){
          redirect('admin/order/new_order'); // If javascript is not enabled, reload the page with new data
      }else{
          echo 'true'; // If javascript is enabled, return true, so the cart gets updated
      }
  }
  /*** Show cart ***/
  function show_cart(){
      $this-&gt;load-&gt;view('admin/order/cart/cart');
  }
  /*** cart Summery ***/
  function show_cart_summary(){
      $this-&gt;load-&gt;view('admin/order/cart/cart_summary');
  }
  
  
  /*** Delete Cart Item ***/
  public function delete_cart_item($id)
  {
      $data = array(
          'rowid' =&gt; $id,
          'qty' =&gt; 0,
      );
      $this-&gt;cart-&gt;update($data);
      $this-&gt;session-&gt;set_flashdata('cart_msg', 'delete');
      redirect('admin/order/new_order/'.$flag ='delete');
  }
  </code></pre>
  
  <p>This is working fine when add product or change its quantity all perfect working but If I add an item with the exact same options more than once to my cart, it replaces instead of increasing the qty of the existing item </p>