Jump to content

[SOLVED] Help: Notice: Undefined index


hass1980

Recommended Posts

Hi

 

Im getting the following error on show_cart.php

 

 

Notice: Undefined index: cart in C:\wamp\www\chapter25\show_cart.php on line 39

 


<?php
  include ('book_sc_fns.php');
  // The shopping cart needs sessions, so start one
  session_start();

  @ $new = $HTTP_GET_VARS['new'];

  if($new)
  {
    //new item selected
    if(!isset($HTTP_SESSION_VARS['cart']))
    {
      $HTTP_SESSION_VARS['cart'] = array();
      $HTTP_SESSION_VARS['items'] = 0;
      $HTTP_SESSION_VARS['total_price'] ='0.00';
    }
    if(isset($HTTP_SESSION_VARS['cart'][$new]))
      $HTTP_SESSION_VARS['cart'][$new]++;
    else 
      $HTTP_SESSION_VARS['cart'][$new] = 1;
    $HTTP_SESSION_VARS['total_price'] =       
                                      calculate_price($HTTP_SESSION_VARS['cart']);
    $HTTP_SESSION_VARS['items'] = calculate_items($HTTP_SESSION_VARS['cart']);

  }
  if(isset($_POST['save'])) {
foreach ($_SESSION['cart'] as $isbn => $qty) {
if($_POST[$isbn] == '0') {
unset($_SESSION['cart'][$isbn]);
} else {
$_SESSION['cart'][$isbn] = $_POST[$isbn];
}
}
$_SESSION['total_price'] = calculate_price($_SESSION['cart']);
$_SESSION['items'] = calculate_items($_SESSION['cart']);
}

do_html_header("Your shopping cart");
if(($_SESSION['cart']) && (array_count_values($_SESSION['cart']))) {
display_cart($_SESSION['cart']);
} else {
echo "<p>There are no items in your cart</p><hr/>";
}
$target = "index.php";
  // if we have just added an item to the cart, continue shopping in that category
  if($new)
  {
    $details =  get_book_details($new);
    if($details['catid'])    
      $target = 'show_cat.php?catid='.$details['catid']; 
  }
  display_button($target, 'continue-shopping', 'Continue Shopping');  

  // use this if SSL is set up
  // $path = $HTTP_SERVER_VARS['PHP_SELF'];
  // $server = $HTTP_SERVER_VARS['SERVER_NAME'];
  // $path = str_replace('show_cart.php', '', $path);
  // display_button('https://'.$server.$path.'checkout.php', 
                    //'go-to-checkout', 'Go To Checkout');  

  // if no SSL use below code
  display_button('checkout.php', 'go-to-checkout', 'Go To Checkout');  

  
  do_html_footer();
?>


 

Link to comment
https://forums.phpfreaks.com/topic/154627-solved-help-notice-undefined-index/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.