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

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');
        }
    }
}

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.

The Cart library is pretty touchy about giving it pre-validated data. Make sure your $price variable does NOT have a dollar sign, and that it is_numeric(). Quantity is fine, as you're hard-coding to 1. id and name are both required as well, so they could cause it to fail silently too.

I would increase logging to 4, and let it tell you where it went wrong (as it will!).