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.

Share this post


Link to post
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. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...