我正在创建一个购物车,其中有四个按钮继续购物、清除购物车、更新购物车和下订单我,我在哪里做,这是我的代码
<?php
include("includes/db.php");
include("includes/functions.php");
if(isset($_REQUEST['command'])=='delete' && $_REQUEST['pid']>0){
remove_product($_REQUEST['pid']);
}
elseif(isset($_REQUEST['command'])=='clear'){
$_SESSION["cart"] = array();
}
elseif($_REQUEST['command']=='update'){
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
$pid=$_SESSION['cart'][$i]['productid'];
$q=intval($_REQUEST['product'.$pid]);
if($q>0 && $q<=999){
$_SESSION['cart'][$i]['qty']=$q;
}
else{
$msg='Some proudcts not updated!, quantity must be a number between 1 and 999';
}
}
}
?>
这是我的 javascript
function update_cart(){
document.form1.command.value='update';
document.form1.submit();
}
这是我的代码
<?php
if(is_array($_SESSION['cart'])){
echo '<tr bgcolor="#FFFFFF" style="font-weight:bold"><td>Serial</td><td>Name</td><td>Price</td><td>Qty</td><td>Amount</td><td>Options</td></tr>';
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
$pid=$_SESSION['cart'][$i]['productid'];
$q=$_SESSION['cart'][$i]['qty'];
$pname=get_product_name($pid);
if($q==0) continue;
?>
<tr bgcolor="#FFFFFF"><td><?php echo $i+1?></td><td><?php echo $pname?></td>
<td>$ <?php echo get_price($pid)?></td>
<td><input type="text" name="product<?php echo $pid?>" value="<?php echo $q?>" maxlength="3" size="2" /></td>
<td>$ <?php echo get_price($pid)*$q?></td>
<td><a href="javascript:del(<?php echo $pid?>)">Remove</a></td></tr>
<?php
}
?>
<tr><td><b>Order Total: $<?php echo get_order_total()?></b></td><td colspan="5" align="right"><input type="button" value="Clear Cart" onclick="clear_cart()"><input type="button" value="Update Cart" onclick="update_cart()"><input type="button" value="Place Order" onclick="window.location='billing.php'"></td></tr>
<?php
}
else{
echo "<tr bgColor='#FFFFFF'><td>There are no items in your shopping cart!</td>";
}
?>