[英]Codeigniter not adding the Items to Cart
I'm trying to add items to the cart when i tried first time its worked but when i did the update function, the insert function not working, Can Anyone Help? 当我第一次尝试使用它时,我正在尝试向购物车中添加物品,但是当我执行更新功能时,插入功能不起作用,有人可以帮忙吗? thanks in advance
提前致谢
This is the code 这是代码
public function addCart($id,$qty,$price,$name,$color,$cat)
{
$size=$this->input->post('size');
$data = array(
'id' => $id,
'qty' => $qty,
'price' => $price,
'name' => $name,
'options' => array('Size' => $size, 'Color' => $color)
);
$res=$this->cart->insert($data);
if($res == true){
$this->session->set_flashdata('success',urldecode($name).' Added in Cart.');
redirect('product/view_all/'.$cat);
}
else{
$this->session->set_flashdata('success','Product Adding Failed :(');
redirect('product/view_all/'.$cat);
}
}
public function viewCart()
{
$data['title']="Products in Cart | DreamShopie.in";
$this->load->view('templates/header',$data);
$this->load->view('templates/menu');
$this->load->view('main_page/cartView',$data);
$this->load->view('templates/footer');
}
public function removeCart($id)
{
$data = array(
'rowid' => $id,
'qty' => 0
);
$this->cart->update($data);
$this->session->set_flashdata('success', 'Item Removed');
redirect('cart/viewCart');
}
假设$ this-> cart是您的数据库,您没有错过数据库名称吗?
$this->cart->insert('db_name', $data);
insert()
and update()
function in the cart
model should be like this cart
模型中的insert()
和update()
函数应像这样
public function insert($data){
return $this->db->insert('table', $data);
}
public function update($data){
$this->db->where('column', $value);
$this->db->set($data);
return $this->db->update('table');
}
I own find the answer , the errorr occurred because the name contains illegal characters from the URL , so I use urldecode function for name 我自己找到答案,发生错误,因为名称包含URL中的非法字符,所以我使用urldecode函数作为名称
Problem solved. 问题解决了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.