Exemplo n.º 1
0
    $p_name = $_POST['p_name'];
    $p_description = $_POST['p_description'];
    $p_class = $_POST['p_class'];
    $p_price = $_POST['p_price'];
    $p_state = 2;
    if ($p_name == null || $p_name == '') {
        $a['msg'] = "产品名称不能为空";
    } else {
        if ($p_price == null || $p_price == '') {
            $a['msg'] = "产品价格不能为空";
        } else {
            if (!preg_match("/^\\d{0,8}\\.{0,1}(\\d{1,2})?\$/", $p_price)) {
                $a['msg'] = "产品价格无效";
            } else {
                $p = new \Ss\Product\Product();
                $p->Create($p_name, $p_description, $p_class, $p_price, $p_state);
                $a['ok'] = '1';
                $a['msg'] = "添加成功";
            }
        }
    }
    echo json_encode($a);
    if ('1' == $a['ok']) {
        echo ' <script>alert("添加成功!")</script> ';
        echo " <script>window.location='product.php';</script> ";
    } else {
        echo " <script>alert('{$a['msg']}')</script> ";
    }
}
?>