title: How to update the quantity of all items in the cart with respect to database?
body: <p>I am doing a shopping cart using code-igniter. While I can do the add cart functions, I'm somewhat confused with how to update them with regards to database. All I want is when I change the item quantity in the cart and click update ,both the cart and database must be updated for that particular item.I tried to do it but couldn't get it.Can someone please enlighten me what to do?</p>
  
  <p>controller code</p>
  
  <pre><code> $this-&gt;load-&gt;model('user_m');
      $result['query'] = $this-&gt;user_m-&gt;get($id); // inserts coresponing item
      foreach ($result['query'] as $row) 
  
          $id = $row-&gt;pid;
          $qty = $a;
          $quan=$row-&gt;quantity;
          $price = $row-&gt;pprice;
      $name = $row-&gt;pname;
  
      $q=$quan-$a;     // for remainig stock i.e total qty-user qty
          $data = array(
          'id' =&gt; $id,
          'qty' =&gt; $qty,
          'price' =&gt; $price,
          'name' =&gt; $name,
          'stock' =&gt;$q
      ); 
      $this-&gt;cart-&gt;insert($data);
  
      $this-&gt;load-&gt;model('user_m');
      $result['qry'] = $this-&gt;user_m-&gt;up_cart($id,$q);
     redirect($_SERVER['HTTP_REFERER']); 
  
  }
  </code></pre>
  
  <p>just tell me how to update pls!</p>