Welcome Guest, Not a member yet? Register   Sign In
Please help with session
#1

[eluser]ppwalks[/eluser]
I have been stuck on this session error for a day now and have tried a million different techniques to try and solve it.

Basically when the session is empty or a new request to the page there is no data in the session variable which means as I load the page it is giving the following errors:

Message: Undefined index: totalprice

Filename: main/cart.php

Line Number: 4,


Severity: Notice

Message: Undefined index: cart

Filename: main/cart.php,

Message: Undefined index: cart

Filename: controllers/welcome.php

Line Number: 79,

It is the code from the wrox book professional codeigniter, i have already read the posts on here but they do not answer my problem I have tried again and again but still nothing so someone please help on this one..

Controller
Code:
function cart($productid = -1) {
     if ($productid > 0){
      $fullproduct = $this->MCart->getProduct($productid);
      $this->MCart->updateCart($productid,$fullproduct);
       redirect('welcome/paving_stone/'.$productid, 'refresh');
       } else {
       $data['title'] = "Venus Stone | Shopping Cart";
        if (count($_SESSION['cart']) == true) {
         $data['cats'] = $this->MCats->getTopCategories();
         $data['main'] = 'cart';
         $this->load->vars($data);
         $this->load->view('index');
      }  else  {
      
       $data['cats'] = $this->MCats->getTopCategories();
        
         $data['main'] = 'cart';
         $this->load->vars($data);
         $this->load->view('index');
         $this->session->set_flashdata('conf_msg', "Your Cart Is Empty.");
       }
      
      }
     }

Model

Code:
function updateCart($productid,$fullproduct){
      $cart = $_SESSION['cart'];
      $totalprice = 0;
       if (count($fullproduct)) {
       if (isset($cart[$productid])) {
        $prevct = $cart[$productid]['count'];
        $prevname = $cart[$productid]['name'];
        $prevprice = $cart[$productid]['price'];
        $cart[$productid] = array(
         'name' => $prevname,
         'price' => $prevprice,
         'count' => $prevct + 1            );
           } else {
         $cart[$productid] = array(
         'name' => $fullproduct['name'],
         'price' => $fullproduct['price'],
         'count' => 1
            );
          }
         foreach ($cart as $id => $product){
           $totalprice += $product['price'] * $product['count'];
            }
         $_SESSION['totalprice'] = $this->format_currency($totalprice);
         $_SESSION['cart'] = $cart;
         $this->session->set_flashdata('conf_msg', "We've added this product to your cart.");
           }
          }

So if anyone has a clue please enlighten me...

If you add a product to the cart the error then stops as it has started a valid session with the variables inside..

Not had a great deal of experience dealing with session data so if some kind person would point me in the right direction I would be ever so grateful...

Thanks in advance Paul


Messages In This Thread
Please help with session - by El Forum - 03-06-2012, 08:27 AM
Please help with session - by El Forum - 03-06-2012, 01:32 PM
Please help with session - by El Forum - 03-07-2012, 07:49 AM
Please help with session - by El Forum - 03-07-2012, 08:53 AM
Please help with session - by El Forum - 03-07-2012, 09:28 AM



Theme © iAndrew 2016 - Forum software by © MyBB