我曾经为我的网站下载过这个购物车脚本。但现在我想为购物车添加一个值,但不知道如何...... :(
我有以下代码:
产品.php
<form method="post" action="cart.php?action=update">
<div class="quantity">
<input type="text" name="qty<?php echo(''.$pinfo->id.''); ?>" value="1" /><span> χ</span>
</div>
<div class="add-quantity">
<input class="nice-s" type="submit" name="product-quantity-submit" value="ORDER" />
</div>
</form>
购物车.php
$cart = $_SESSION['cust_cart'];
if(isset($_GET['action'])) {
$action = sanitize($_GET['action']);
switch ($action) {
case 'add':
if ($cart) {
$cart .= ','.$_GET['id'];
} else {
$cart = $_GET['id'];
}
break;
case 'delete':
if ($cart) {
$items = explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($_GET['id'] != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
$cart = $newcart;
}
break;
case 'update':
/* if ($cart) { */
$newcart = '';
foreach ($_POST as $key=>$value) {
if (stristr($key,'qty')) {
$id = str_replace('qty','',$key);
$items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($id != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
for ($i=1;$i<=$value;$i++) {
if ($newcart != '') {
$newcart .= ','.$id;
} else {
$newcart = $id;
}
}
}
}
/* } */
$cart = $newcart;
break;
}
}
$_SESSION['cust_cart'] = $cart;
我想知道的是;如何通过 product.php 页面向购物车添加另一个值,其中包含以下字段:
<div class="size">
<select name="size">
<option value="16 INCH">16 INCH</option>
<option value="19 INCH">19 INCH</option>
<option value="22 INCH">22 INCH</option>
</div>
提前谢谢!!二)