Example #1
0
    if (empty($_goods['g_name'])) {
        ym_manage("goods.php?act=modify&id={$id}", '商品名称不能为空!');
    }
    if (empty($_goods['g_name']) > 40) {
        ym_manage("goods.php?act=modify&id={$id}", '商品名称过长,不能超过20个字符');
    }
    //价格验证
    if (!is_numeric($_goods['g_price'])) {
        ym_manage("goods.php?act=modify&id={$id}", '商品价格必须是数值!');
    }
    //库存验证
    if (!is_numeric($_goods['g_inv']) || $_goods['g_inv'] < 0) {
        ym_manage("goods.php?act=modify&id={$id}", '商品库存必须是大于0的整数!');
    }
    //商品分类验证
    if ($_goods['c_id'] == 0) {
        ym_manage("goods.php?act=modify&id={$id}", '必须选择所属商品分类!');
    }
    //合理性验证
    $goods = new Goods();
    //var_dump($_goods['g_code']);exit;
    // var_dump($_goods['g_price']);exit;
    //判断插入数据库
    if ($goods->updateGoodsById($id, $_goods)) {
        //成功:
        ym_manage("goods.php", '商品修改成功!');
    } else {
        //失败
        ym_manage("goods.php?act=modify&id={$id}", '商品修改失败!');
    }
}