Jump to content
Larry Ullman's Book Forums

Recommended Posts

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

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

 Share

×
×
  • Create New...