robert1962 Posted May 30, 2015 Share Posted May 30, 2015 Hi. I'm having a problem with the code in checkout.php in Chapter 19. For some reason, I get the following errors: Notice: Undefined index: cart in C:\xampp\htdocs\php\PHPandMySQL\ch19\checkout.php on line 26. Warning: Invalid argument supplied for foreach() in C;\xampp\htdocs\php\PHPandMySQL\ch19\checkout.php on line 26. Notice: Undefined index: cart in C;\xampp\htdocs\php\PHPandMySQL\ch19\checkout.php on line 37. I have included the header.html file. This starts the session. So the session variable is set. Here is my code for the foreach function on line 26: foreach($_SESSION['cart'] as $pid => $item) { ... } Here is the if conditional for line 37: if($affected == count($_SESSION['cart'])) { ... } Why am I getting these notices and warnings? The code appears correct. Link to comment Share on other sites More sharing options...
robert1962 Posted May 30, 2015 Author Share Posted May 30, 2015 The orders are processing, but the order_contents are not. Link to comment Share on other sites More sharing options...
Larry Posted June 1, 2015 Share Posted June 1, 2015 The most likely cause is that your session ID is being changed, and so your cart is empty. I'd being debugging this by verifying the session ID, and the session contents, on each page to see that both are being maintained. Link to comment Share on other sites More sharing options...
Recommended Posts