未定义的索引:购物车的购物车

时间:2016-06-15 09:35:10

标签: php

我一直在关注购物车功能的Book-O-Rama示例,但我似乎无法让它发挥作用。当我进入show_cart.php页面时出现以下错误。

Notice: Undefined index: cart in C:\wamp\www\site\show_cart.php on line 32
Call Stack
#   Time    Memory  Function    Location
1   0.0005  138616  {main}( )   ...\show_cart.php:0

Fatal error: Call to undefined function display_button() in C:\wamp\www\site\show_cart.php on line 45
Call Stack
#   Time    Memory  Function    Location
1   0.0005  138616  {main}( )   ...\show_cart.php:0

我的代码是:

<?php 
 require_once('require_fns.php');
 session_start();
 @$new = $_GET['new'];
 if($new) {
    //new item selected
    if(!isset($_SESSION['cart'])) {
      $_SESSION['cart'] = array();
      $_SESSION['items'] = 0;
      $_SESSION['price'] ='0.00';
    }
    if(isset($_SESSION['cart'][$new])) {
      $_SESSION['cart'][$new]++;
    } else {
      $_SESSION['cart'][$new] = 1;
    }
    $_SESSION['price'] = calculate_price($_SESSION['cart']);
    $_SESSION['items'] = calculate_items($_SESSION['cart']);
  }
  if(isset($_POST['save'])) {
    foreach ($_SESSION['cart'] as $subid => $qty) {
      if($_POST[$subid] == '0') {
        unset($_SESSION['cart'][$subid]);
      } else {
        $_SESSION['cart'][$subid] = $_POST[$subid];
      }
    }
    $_SESSION['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_subscription_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 = $_SERVER['PHP_SELF'];
  // $server = $_SERVER['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_user_menu();

do_html_footer();
?>

可能我只是因为拼错错误而错过了什么,但我不知道如何修复它

1 个答案:

答案 0 :(得分:0)

更新show_cart.php中的第32行

.job.hot:hover, #ja-jobs-widget a {
    color: #fff;
}