i have some problem in my libraries cart when i try to insert my product into the cart. could you help me.
here is my code link for product into the cart.
<form method="post" action="<?php echo base_url(); ?>cart/add">
<span style="width: 70%;"><input type="submit" class="fa fa-cart-arrow-down btn btn-primary btn-sm btn-block" value="Add to Cart" <?php echo "$mati";?>/></span>
<input type="hidden" name="id_books" value="<?php echo $row->id_books; ?>"/>
<input type="hidden" name="id_category" value="<?php echo $row->id_category; ?>"/>
<input type="hidden" name="title" value="<?php echo $row->title; ?>"/>
<input type="hidden" name="images" value="<?php echo $row->images; ?>"/>
<input type="hidden" name="price" value="<?php echo $total; ?>"/>
<input type="hidden" name="qty" value="1"/>
</form>
and this is cart controller
class Cart extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->library(array('cart'));
session_start();
}
function index()
{
$data['menu'] = 'cart';
$this->load->view('v_cart', $data);
}
function add()
{
$data = array(
'id_books' => $this->input->post('id_books'),
'id_category' => $this->input->post('id_category'),
'qty' => $this->input->post('qty'),
'price' => $this->input->post('price'),
'images' => $this->input->post('images'),
'title' => $this->input->post('title'));
$this->cart->insert($data);
/*print_r($data);*/
/*echo "<meta http-equiv='refresh' content='0; url=".base_url()."cart/'>";*/
redirect('cart','refresh');
}
and this is cart view
<?php if($cart = $this->cart->contents()):
?>
<?php echo form_open('cart/update'); ?>
<table id="cart-table" class="table table-condensed">
<thead>
<tr>
<th>Action</th>
<th>Image</th>
<th>Product</th>
<th>Price</th>
<th>Quanity</th>
<th>Sub Total</th>
</tr>
</thead>
<tbody>
<?php $i = 1; ?>
<?php foreach($cart as $item): /* $title = str_replace(' ', '-', $item['title']); ?>
<?php $price = $row['price']; $jumlah_desimal = "0"; $pemisah_desimal =""; $pemisah_ribuan =".";?>
<?php /*echo form_hidden('rowid[]', $item['rowid']);*/
echo form_hidden($i.'[rowid]', $item['rowid']); ?>
<tr>
<th class="product-remove">
<a class="remove" title="Remove this product" href="<?php echo base_url().'cart/delete/'.$item['rowid'];?>">×</a>
</th>
<th>
<div class="media">
<div class="relative">
<a href="shop-single.html" title="">
<img src="<?php echo base_url().$item['images'];?>" alt=""/>
</a>
</div>
</div><!-- end media -->
</th>
<th>
<a href="<?php echo base_url();?>books/detail/<?php echo $title;?>/<?php echo $item['id_category'];?>/<?php echo $item['id_books'];?> "><?php echo $item['title'];?></a>
</th>
<td>Rp. <?php echo $this->cart->format_number($item['price']); /*echo rupiah($item['price']); */?></td>
<td>
<?php echo form_input(array('name' => $i.'[qty]', 'value' => $item['qty'], 'maxlength' => '3', 'class' => 'j')); ?> pcs
</td>
<td>
Rp. <?php echo $this->cart->format_number($item['subtotal']);/*echo rupiah($item['subtotal']);*/ ?>
</td>
</tr>
<?php $i++; ?>
<?php endforeach; ?>
<tr>
<td colspan="5" style="text-align: right!important;"><b>Total </b>(biaya buku)</td>
<td>
Rp. <?php echo $this->cart->format_number($this->cart->total()); ?>
</td>
</tr>
</tbody>
</table>
<?php
echo form_close();
else:
echo 'Sorry, Your Cart is empty';
endif;
?>
the result always show
Sorry, Your Cart is empty
where is the bug? anybody can help me :) thanks :)