我已经设置了购物车系统,只需在购物车中添加东西(不需要购买)。这是我的cart.php代码
<?php
session_start();
include 'connection.php';
include 'item.php';
$sql = "SELECT * FROM apps";
$result = mysqli_query($con, $sql);
$product = mysqli_fetch_object($result);
if(isset($_GET['AppName'])) {
$item = new Item();
$item->AppName = $product->AppName;
$item->AndroidPrice = $product->AndroidPrice;
$item->iPhonePrice = $product->iPhonePrice;
$item->quantity = 1;
$_SESSION['cart'][] = $item;
}
?>
<table cellpadding="2" cellspacing="2" border="1">
<tr>
<th>AppName</th>
<th>AndroidPrice</th>
<th>iPhonePrice</th>
<th>quantity</th>
<th>Sub Total</th>
</tr>
<?php
$cart = unserialize(serialize($_SESSION['cart']));
for ($i=0; $i<count($cart); $i++)
?>
<tr>
<td><?php echo $cart[$i]->AppName; ?></td>
<td><?php echo $cart[$i]->AndroidPrice; ?></td>
<td><?php echo $cart[$i]->iPhonePrice; ?></td>
<td><?php echo $cart[$i]->quantity; ?></td>
<td><?php echo $cart[$i]->price * $cart[$i]->quantity; ?></td>
</tr>
</table>
我收到的错误是注意:未定义的索引:第31行的E:\ xampp \ htdocs \ cart.php中的购物车。
第31行是$ cart = unserialize(serialize($ _ SESSION ['cart'])); - 我做错了什么?
如果需要,可以提供更多信息。我的item.php:
<?php
class item{
var $AppName;
var $AndroidPrice;
var $iPhonePrice;
var $quantity;
}
?>
以及应该将商品添加到购物车的应用页面。
<?php
include 'connection.php';
$sql = "SELECT * FROM apps";
$result = mysqli_query($con, $sql);
?>
<table cellpadding="2" cellspacing="2" border="0">
<tr>
<th>AppName</th>
<th>AndroidPrice</th>
<th>iPhonePrice</th>
<th>Description</th>
<th>Noofdownloads</th>
<th>Buy</th>
</tr>
<?php
while ($product = mysqli_fetch_object($result)){ ?>
<tr>
<td><?php echo $product->AppName; ?></td>
<td><?php echo $product->AndroidPrice; ?></td>
<td><?php echo $product->iPhonePrice; ?></td>
<td><?php echo $product->Description; ?></td>
<td><?php echo $product->Noofdownloads ?></rd>
<td><a href="cart.php">Add to Cart</a></td>
</tr>
<?php } ?>
</table>
将会感激任何帮助。我非常擅长PHP和初学者,所以请帮帮我D: