drbz99867 2012-02-18 18:30
浏览 31
已采纳

无法将数据添加到数据库中的变量(仅限字符串)

I have a product page and when the user clicks the "add to cart" button the function below is triggered and the desk_id and price is parsed into the function. The variables are then referenced to the carts data array which is inserted into the cart.

My problem is that nothing gets added to the cart with these variables in the $data array but it works fine when I just add strings. I have tested to make sure the database returns the product title correctly and have tried converting these variables to strings but it makes no difference.

    function request_desk_booking($desk_id, $price){
    $this->load->model('search_model');

    //Query database to get desk title because parsing strings through the url does not work
    if($query = $this->search_model->desk_details_cart($desk_id)){

        //convert title to string
        $title =  $query['company'].', '.$query['Town'];
        $name =  (string) $title;

        //check to make sure values are not null
        if($desk_id !== null && $price !== null){

            $this->load->library('cart');

            $data = array(
                   'id'      => $desk_id,
                   'qty'     => 1,
                   'price'   => $price,
                   'name'    => $name
            );

            //insert data into cart
            $this->cart->insert($data);
            $this->load->view('request_booking', $data);

        }else{
            $this->load->view('request_booking');
        }
    }
}
  • 写回答

2条回答 默认 最新

  • duanhe6718 2012-02-19 13:27
    关注

    The ', ' on $title was causing the problem. All fixed now when I removed it. Also it appears that the cart contents must always have an id, qty, price and name. Remove any of these and it will not add the item to the cart.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程