File manager - Edit - /var/www/order.cmtc.ac.th/user/update_cart_ajax.php
Back
<?php session_start(); include('../config/db.php'); if(isset($_POST['pid']) && isset($_POST['qty'])){ $pid = intval($_POST['pid']); $qty = intval($_POST['qty']); if($qty <= 0) unset($_SESSION['cart'][$pid]); else $_SESSION['cart'][$pid] = $qty; // คำนวณยอดรวมใหม่ $cart_total = 0; $item_total = 0; $res = $conn->query("SELECT id, price FROM products WHERE id IN (".implode(',', array_keys($_SESSION['cart'])).")"); while($r = $res->fetch_assoc()){ $p = $r['id']; $item_total_temp = $r['price'] * $_SESSION['cart'][$p]; if($p == $pid) $item_total = number_format($item_total_temp,2); $cart_total += $item_total_temp; } echo json_encode([ 'item_total' => number_format($item_total,2), 'cart_total' => number_format($cart_total,2) ]); } ?>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.41 |
proxy
|
phpinfo
|
Settings