Normally I can add the array data to cart by giving values in it and I can fetch the data. But I issue is I cannot add the data which are coming from database or by giving the values from views.
Please give me the solution.
Below are my code
View:
< a href="<?php echo site_url('product/addtocart/'.$row->id)?>">
Controller:
function addtocart(){
$id = $this->uri->segment(3);
$data['post'] = $this->model->get_product(
$id);
foreach($data as $item){
$name = $item->product_name;
$price = $item->price;
$image = $item->image;
}
$data = array(
'id' => $id,
'name' => $name,
'price' => $price,
'image' => $image,
'qty' => 1);
$this->cart->insert($data);
print_r($this->cart->contents());
}
I couldn't find any errors in code but why its not adding???????