title: Add and show list product in cart codeigniter
body: <p>I have a problem when I add some products to cart, but then when I want to fetch contents of the cart I find it is empty.</p>
  
  <p>this is my controller : </p>
  
  <pre><code>public function add_to_cart(){
  
      $insert_data = array( 
       'id' =&gt; $this-&gt;input-&gt;post('id'),
       'name' =&gt; $this-&gt;input-&gt;post('name'),
       'price' =&gt; $this-&gt;input-&gt;post('price'),
       'qty' =&gt; $this-&gt;input-&gt;post('qty') );
  
       // This function add items into cart.
      $this-&gt;cart-&gt;insert($insert_data);
  
  
  }
  </code></pre>
  
  <p>and this is my form to add new product to cart :</p>
  
  <pre><code>&lt;div class="button-group"&gt;
                    &lt;form method="POST" action="&lt;?php echo base_url().'add_to_cart'; ?&gt;"&gt;
                    &lt;div style="display:none"&gt;
                    &lt;input type="hidden" name="&lt;?php echo $this-&gt;security-&gt;get_csrf_token_name(); ?&gt;" value="&lt;?php echo $this-&gt;security-&gt;get_csrf_hash();?&gt;" /&gt;
                    &lt;/div&gt; 
                    &lt;input type="hidden" name="&lt;?php echo $this-&gt;security-&gt;get_csrf_token_name(); ?&gt;" value="&lt;?php echo $this-&gt;security-&gt;get_csrf_hash(); ?&gt;"&gt;
                      &lt;input type="number" name="qty" id="&lt;?php echo $ligneBase-&gt;id;?&gt;"&gt;
                      &lt;input type="hidden" name="name" value="&lt;?php echo $ligneBase-&gt;name;?&gt;"&gt;
                      &lt;input type="hidden"  name="price"  value="&lt;?php echo $ligneBase-&gt;price;?&gt;"&gt;
                      &lt;input type="hidden"  name="id"  value="&lt;?php echo $ligneBase-&gt;id;?&gt;"&gt;
                        &lt;input class="add_cart" type="submit" value="Add to cart"&gt;
                        &lt;div class="add-to-links"&gt;
                    &lt;/form&gt;
                  &lt;/div&gt;
  </code></pre>
  
  <p>and this is my cart in header.php :</p>
  
  <pre><code>&lt;table class="table"&gt;
                  &lt;tbody&gt;
                  &lt;div id="text"&gt;
                    &lt;?php $cart_check = $this-&gt;cart-&gt;contents();
  
                    // If cart is empty, this will show below message.
                    if(empty($cart_check)) {
                    echo '&lt;h4 align="center"&gt;No Product in cart, To add products to your shopping cart click on "Add to Cart" Button&lt;/h4&gt;';
                    } ?&gt; 
                  &lt;/div&gt;
  
                    &lt;?php
                       $cart = $this-&gt;cart-&gt;contents();
                       foreach($cart as $indice =&gt; $ligneBase){
                    ?&gt;
                    &lt;tr&gt;
                      &lt;td class="text-center"&gt;&lt;a href="product.html"&gt;&lt;img class="img-thumbnail" title="Xitefun Causal Wear Fancy Shoes" alt="Xitefun Causal Wear Fancy Shoes" src="image/product/sony_vaio_1-50x50.jpg"&gt;&lt;/a&gt;&lt;/td&gt;
                      &lt;td class="text-left"&gt;&lt;a href="product.html"&gt;&lt;?php echo $ligneBase-&gt;id;?&gt;&lt;/a&gt;&lt;/td&gt;
                      &lt;td class="text-right"&gt;x 1&lt;/td&gt;
                      &lt;td class="text-right"&gt;&lt;?php echo $ligneBase-&gt;name;?&gt; &lt;/td&gt;
                      &lt;td class="text-center"&gt;&lt;button class="btn btn-danger btn-xs remove" title="Remove" onClick="" type="button"&gt;&lt;i class="fa fa-times"&gt;&lt;/i&gt;&lt;/button&gt;&lt;/td&gt;
                    &lt;/tr&gt;
  
                  &lt;?php
                    }
                  ?&gt;
  
  
                  &lt;/tbody&gt;
                &lt;/table&gt;
  </code></pre>