Exemple #1
1
<?php

session_start();
$id = $_POST["id"];
$nombre = $_POST["nombre"];
$precio = $_POST["precio"];
$cantidad = $_POST["cantidad"];
$img = $_POST["imagen"];
addcart($id, $nombre, $precio, $cantidad, $img);
function addcart($id, $nombre, $precio, $cantidad, $img)
{
    if (!isset($_SESSION["cart"])) {
        $_SESSION["cart"] = array();
    } else {
        $_SESSION["cart"][$id] = array("{$nombre}", $precio, $cantidad, "{$img}");
    }
}
//echo "Successfull !!!";
foreach ($_SESSION as $item => $value) {
    echo "<h5>shoopingcart:</h5>";
    //echo $item . " => ";
    foreach ($value as $item => $value) {
        echo "({$item}";
        foreach ($value as $value) {
            echo "," . $value;
        }
        echo ")<br />";
    }
}
        ?>
";
</script>

<?php 
        return;
    }
}
if ($_GET['del'] && is_numeric($_GET['del'])) {
    delcart($_GET['del']);
    $action = "del";
} elseif ($_GET['empty'] == 1) {
    setcookie("shopcartinfo", time() - 300);
    $action = "empty";
} elseif ($_GET['add']) {
    addcart($_GET['add'], $_GET['num']);
    $action = "add";
} elseif ($_POST['save']) {
    $arr_pid = $_POST['pid'];
    $arr_num = $_POST['num'];
    foreach ($arr_num as $id => $num) {
        if (!is_numeric($num) || $num <= 0) {
            ?>

   <script>
   alert("QTY. is not correct!");
   location.href="cart.php";
   </script>   

		<?php 
            return;
     break;
 case "checkTime":
     $sql1 = "select * from qiyu_delivertime where time(now())>=delivertime_starttime and time(now())<=delivertime_endtime";
     $rs = mysql_query($sql1);
     $row = mysql_fetch_assoc($rs);
     if (!$row) {
         echo "N";
     } else {
         echo "S";
     }
     break;
 case "addCart":
     $shopID = sqlReplace(trim($_POST['shopID']));
     $foodID = sqlReplace(trim($_POST['foodID']));
     $desc = empty($_POST['desc']) ? '' : HTMLEncode(trim($_POST['desc']));
     addcart($foodID, $shopID, $desc);
     echo "S";
     break;
 case "getCart":
     $shopID = sqlReplace(trim($_POST['shopID']));
     $foodID = sqlReplace(trim($_POST['foodID']));
     $time1 = sqlReplace(trim($_POST['time1']));
     $time2 = sqlReplace(trim($_POST['time2']));
     $spotID = empty($_POST['spotID']) ? '0' : sqlReplace(trim($_POST['spotID']));
     $circleID = empty($_POST['circleID']) ? '0' : sqlReplace(trim($_POST['circleID']));
     $addressID = empty($_POST['addressID']) ? '0' : sqlReplace(trim($_POST['addressID']));
     $orderType = empty($_SESSION['qiyu_orderType']) ? '' : $_SESSION['qiyu_orderType'];
     $deliverfee = '';
     $sendfee = '';
     $deliverfee_r = '';
     $sendfee_r = '';
Exemple #4
0
$act = sqlReplace(trim($_GET['act']));
switch ($act) {
    case "add":
        $url = empty($_SESSION['user_url']) ? '' : $_SESSION['user_url'];
        if (empty($url)) {
            $url = "index.php";
        }
        $shopID = sqlReplace(trim($_GET['id']));
        $foodID = sqlReplace(trim($_GET['foodID']));
        $lableID = empty($_GET['lableID']) ? 0 : sqlReplace(trim($_GET['lableID']));
        $ftID = empty($_GET['ftID']) ? 0 : sqlReplace(trim($_GET['ftID']));
        //菜的大类id
        $sql1 = "select shop_id from qiyu_shop inner join qiyu_shopspot on shopspot_shop=shop_id";
        $sql1 .= " inner join qiyu_delivertime on delivertime_shop=shop_id and time(now())>=delivertime_starttime and time(now())<=delivertime_endtime";
        $sql1 .= " and shop_id=" . $shopID . " and shop_status='1'";
        $rs = mysql_query($sql1);
        $row = mysql_fetch_assoc($rs);
        if (!$row) {
            alertInfo('现在不能点餐', '', 1);
        }
        addcart($foodID, $shopID);
        Header("Location: " . $url . " ");
        break;
    case "del":
        $id = sqlReplace(trim($_GET['id']));
        $shopID = sqlReplace(trim($_GET['shopID']));
        delcart($id, $shopID);
        //删除购物车
        alertInfo('删除成功', '', 1);
        break;
}
<?php

session_start();
ob_start();
include "cart.php";
$idSP = $_POST["idSP"];
$DonGia = $_POST["DonGia"];
$Hinh = $_POST['Hinh'];
$SoLuong = intval($_POST["SoLuong"]);
if ($SoLuong <= 0) {
    $SoLuong = 1;
}
addcart($idSP, $SoLuong, $DonGia, $Hinh);
//header('location:".$_SERVER['HTTP_REFERER']');
echo "<script language='javascript'>location.href='" . $_SERVER['HTTP_REFERER'] . "';</script>";