PHP未定义索引

PHP未定义索引,php,Php,呵呵,我收到了这个错误信息。我到处都找了,但不知道怎么修?我是个初学者,所以我真的很困惑。提前谢谢 注意:第3行未定义索引:cart in/nas/students/j/j39 green/unix/public_html/ISD5/inc/functions.inc.php 您的购物车中没有商品 <?php function writeShoppingCart() { $cart = $_SESSION['cart']; if (!$cart) { return '<p&g

呵呵,我收到了这个错误信息。我到处都找了,但不知道怎么修?我是个初学者,所以我真的很困惑。提前谢谢

注意:第3行未定义索引:cart in/nas/students/j/j39 green/unix/public_html/ISD5/inc/functions.inc.php

您的购物车中没有商品

<?php
function writeShoppingCart() {
$cart = $_SESSION['cart'];
if (!$cart) {
    return '<p>You have no items in your shopping cart</p>';
} else {
    // Parse the cart session variable
    $items = explode(',',$cart);
    $s = (count($items) > 1) ? 's':'';
    return '<p>You have <a href="cart.php">'.count($items).' item'.$s.'  in your shopping cart</a></p>';
}
}

这意味着您的会话不包含
$\u会话['cart']

请尝试以下方法:

$cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : false;

这意味着您的会话不包含
$\u会话['cart']

请尝试以下方法:

$cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : false;
试试这个:

$cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : NULL;
试试这个:

$cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : NULL;

如果未设置
$\u会话['cart']
,它将抛出该警告

尝试:


如果未设置
$\u会话['cart']
,它将抛出该警告

尝试:


尝试使用以下方法初始化$\u会话:

$_SESSION['cart'] = 0;    // zero items in cart

尝试使用以下方法初始化$\u会话:

$_SESSION['cart'] = 0;    // zero items in cart
使用“空”:

使用“空”:


这意味着$\u会话超全局数组中不存在键“cart”

如果该值不存在没有问题,则应执行以下操作:

$cart = false;
if (isset($_SESSION['cart'])) {
    $cart = $_SESSION['cart'];
}
在PHP中,您可以使用称为三元运算符的东西,但由于您是一名初学者,我不想炮轰您


在开发模式下,可以显示错误,但您应该阅读有关禁用错误(错误报告)和记录错误(错误日志())的更多信息,以便在不警告访问者的情况下检查错误。

这意味着$\u会话超全局数组中不存在密钥“cart”

如果该值不存在没有问题,则应执行以下操作:

$cart = false;
if (isset($_SESSION['cart'])) {
    $cart = $_SESSION['cart'];
}
在PHP中,您可以使用称为三元运算符的东西,但由于您是一名初学者,我不想炮轰您


在开发模式下,可以显示错误,但您应该阅读更多有关禁用错误(错误报告)和记录错误(错误日志())的信息,以便在不警告访问者的情况下检查错误。

错误在functions.Inc.php中,而不是您的代码错误在functions.Inc.php中,而不是您的代码