e commerce - Display item list in shopping cart using PHP -


with foreach loop i'm trying connect database , display in list products have been added cart. each product has product id correctly working , being stored in session variable through cart.php. can't figure out how connect database display information gathered product added - tried doing var_dump $session['cart'] , prints out null after use "add" button in cart.php.

<div class="row">     <h4>shopping cart</h4>             <?php              foreach($_session['cart'] $proid => $proq) {                  // $proid product id , $proq quantity                 // use $proid select product detail database                  }             ?> </div>     <!--below cart.php page-->     <?php     session_start();      $productid = $_get['product'];     $action = $_get['action'];      switch($action) {      case "add":     $_session['cart'][$productid]++;     break;      case "remove":     $_session['cart'][$productid]--;     if($_session['cart'][$productid] == 0) unset($_session['cart'][$productid]);     break;      case "empty":     unset($_session['cart']);     break;     }     header("location: browse.php");       ?> 

based on explanation, trying retrieve data session value populate database query.

however, when for loop executes, have not de-serialized session data memory (so cannot accessed , null values).

you need start session before for loop:

session_start(); foreach($_session['cart'] $proid => $proq) { 

please see more information in php manual

also, can configure php start session automatically if desired (see more details in manual linked above), keep in mind have performance impact on pages not rely on session data.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -