luckyirish470 Posted May 17, 2010 Share Posted May 17, 2010 Hello, I'm trying to get my shopping cart script to display the item picture, info, and price for every item selected while calculating a total price for all the items as the cart is updated. The two related scripts are in .inc files and everything looks right to me...but when I run the scripts nothing is displayed and the total price displayed is $0. I am using $_SESSION variables and my guess is I've done something wrong with them...but I have been staring at the code for weeks now trying to figure out what it is and I am running out of hair to pull out! Any help would be GREATLY appreciated, thank you! Here are the script .inc files.... ------------------------------------------------------------------------------------------------------ PRODUCT DISPLAY PAGE...... ------------------------------------------------------------------------------------------------------ <?php session_start(); if(!isset($_SESSION['auth']) or $_SESSION['auth'] != "yes") { header("location: loginfinal.php"); header('Content-type: image/jpg'); exit(); } ?> <?php /* Program name: page_links.inc * Description: file builds a list of links from the database */ ini_set("display_errors","on"); error_reporting(E_ALL | E_STRICT); ini_set("include_path","./includes"); ?> <html> <head><title>Customer Products</title></head> <body> <?php include("dbinfo.inc"); $cxn = mysqli_connect($host,$user,$passwd,$dbname) or die ("couldn't connect to server"); $query = "SELECT * FROM products WHERE category='$_GET[category]'"; $result = mysqli_query($cxn,$query) or die("Couldn't execute query ".mysqli_error($cxn)); while($row = mysqli_fetch_assoc($result)) { extract($row); echo " <ul><li> <img src='images/$thumbnail'/> <br /> <a href='shoppingcart.php?productnumber=$productnumber&thumbnail=$thumbnail&productname=$productname&price=$price'>$productname </a><br /> $description <br/> \$$price </li> </ul>"; } ?> </body></html> ------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------ SHOPPING CART SCRIPT ------------------------------------------------------------------------------------------------------ <?php session_start(); if(!isset($_SESSION['auth']) or $_SESSION['auth'] != "yes") { header("location: loginfinal.php"); exit(); } ?> <?php /* Program name: shoppingcart.inc * Description: file builds a list of links from the database */ ini_set("display_errors","on"); error_reporting(E_ALL | E_STRICT); ini_set("include_path","./includes"); ?> <html> <head><title>Shopping Cart</title></head> <body> <?php $total=0; include("dbinfo.inc"); $cxn = mysqli_connect($host,$user,$passwd,$dbname) or die ("couldn't connect to server"); if(!isset($_SESSION['items'])) { $_SESSION['items'][]= array('productnumber'=>'$productnumber', 'thumbnail'=>'$thumbnail', 'productname'=>'$productname', 'price'=> '$price'); $items = $_SESSION['items']; } foreach($_SESSION['items'] as $productnumber) { $query = "SELECT * FROM products WHERE productnumber='$_SESSION[items]'"; //should be $_Get[productnumber] $result = mysqli_query($cxn,$query) or die("Couldn't execute query ".mysqli_error($cxn)); while($row = mysqli_fetch_assoc($result)) { extract($row); echo " <ul><li><img src='images/$_SESSION[thumbnail]'/> <br /> $_SESSION[productname] <br/> \$$_SESSION[price] </li> </ul>"; $total= $total + $price; } } ?> <?php echo" <h3> Total Price </h3> \$$total <br /> <a href='thankyou.php'>Submit Order </a> <a href='products.php?total=$total'>Keep Shopping </a>"; ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/202005-display-shopping-cart-_session-variables-and-calculate-total-price/ Share on other sites More sharing options...
Pikachu2000 Posted May 17, 2010 Share Posted May 17, 2010 Have you tried a print_r($_SESSION) to see if the values you think should be there are indeed there? Link to comment https://forums.phpfreaks.com/topic/202005-display-shopping-cart-_session-variables-and-calculate-total-price/#findComment-1059331 Share on other sites More sharing options...
luckyirish470 Posted May 18, 2010 Author Share Posted May 18, 2010 Thank you for the reply, I just tried the print $_SESSION[items]; and the only thing that was displayed was "Array". Any idea where I'm going wrong? Thanks again! Link to comment https://forums.phpfreaks.com/topic/202005-display-shopping-cart-_session-variables-and-calculate-total-price/#findComment-1059873 Share on other sites More sharing options...
scampbell Posted May 18, 2010 Share Posted May 18, 2010 print_r not print Link to comment https://forums.phpfreaks.com/topic/202005-display-shopping-cart-_session-variables-and-calculate-total-price/#findComment-1059935 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.