日期:2014-05-17  浏览次数:20625 次

来请教一个问题
咱在做一个购物车
购物车页面cart.php

<?php
define('ACCESE',1);
require('../init.php');

$_GET['gid'] = (int)$_GET['gid'];
$_GET['num'] = (int)$_GET['num'];

$goods = new goodsModel();
$goods->db();
$cart = cart::getCart();

switch($_GET['act']) {
        //添加商品
        case 'buy':{
                $result = $goods->select_goods("g_id = $_GET[gid] and g_sale=1 and g_del=0");
                $g = $goods->db->fetch_array($result);
                //有此商品
                if(!empty($g)) { //判断商品是否存在
                        if($g['g_no'] < $_GET['num']) { //判断库存
                                $type = 'error';
                                $msg = '放到购物车添加失败(可能是库存不足或者管理员私吞了)';
                                include(ROOT.'view/home/tip.html');
                                exit;
                        }
                        //商品存在
                        $cart->addItem("$g[g_id]","$g[g_name]","$g[g_price]","$_GET[num]");   //----------------------此行报错
                } else {
                        $type = 'error';
                        $msg = '放到购物车添加失败(可能是下架、删除或者管理员私吞了)';
                        include(ROOT.'view/home/tip.html');
                        exit;
                }
                break;
        }

}