2016-06-15 20 views
-1

私はショッピングカート機能の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(); 
?> 

が、私はどのように知りませんそれを修正してください

+0

[PHP: "通知:未定義変数"と "通知:未定義インデックス"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined)の可能な複製-index) – Epodax

答えて

0

アップデートライン番号32 in show_cart.php

if(isset($_SESSION['cart']) && (array_count_values($_SESSION['cart']))) { 
+0

助けてくれてありがとう:) – JonnySmith

関連する問題