<? session_start(); include('config.inc.php'); session_register("cart"); if($_SESSION['ID_User'] == "") { echo "<script language='javascript'>alert('Please Login');history.back();</script>"; exit(); } $strSQL = "SELECT * FROM register WHERE ID_User = '".$_SESSION['ID_User']."' "; $objQuery = mysql_query($strSQL); $objResult = mysql_fetch_array($objQuery); if($_REQUEST['act']=='add' && !empty($_REQUEST['ID_Product'])) { if(isset($_SESSION['cart'][$_REQUEST['ID_Product']])) { $_SESSION['cart'][$_REQUEST['ID_Product']]++; } else { $_SESSION['cart'][$_REQUEST['ID_Product']]=1; } } if($_REQUEST['act']=='remove' && !empty($_REQUEST['ID_Product'])) { unset($_SESSION['cart'][$_REQUEST['ID_Product']]); } if($_REQUEST['act']=='update') { foreach($_POST['qty'] as $_SESSION['ID_Product']=>$_SESSION['qty']) { $_SESSION['cart'][$_SESSION['ID_Product']]=$_SESSION['qty']; } } ?> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <form id="frmcart" name="frmcart" method="post" action="?act=update"> <table width="600" border="1" align="center"> <tr> <td>Cart</td> </tr> <tr> <td>Product</td> <td width="117">Price</td> <td width="25">Unit</td> <td width="42">include</td> <td width="51">Remove</td> </tr> <? $total=0; if(!empty($_SESSION['cart'])) { foreach($_SESSION['cart'] as $_SESSION['ID_Product']=>$_SESSION['qty']) { $sql = "SELECT * FROM product where ID_Product = '".$_SESSION['ID_Product']."' "; $query = mysql_query($sql) or die ("error=$sql"); $objResult = mysql_fetch_array($query); $_SESSION['P_Price'] = $objResult['P_Price']; $sum = $_SESSION['P_Price']*$_SESSION['qty']; $_SESSION['total'] += $sum; if($_SESSION['total']>=10000) { $sum1 = $_SESSION['total']*0.05; $sum2 = $_SESSION['total'] - $sum1; } ?> <tr> <td width="334"><?=$objResult["P_name"]?></td> <td width="46" align="right"><?=$_SESSION['P_Price']?></td> <td width="57" align="right"> <input type="text" name="qty[<?=$_SESSION['ID_Product']?>]" value="<?=$_SESSION['qty']?>" size="2" /> </td> <td width="93" align="right"><?=$sum?></td> <td><a href="order.php?ID_Product=<?=$_SESSION['ID_Product']?>&act=remove">remove</td> </tr> <? } ?> <tr> <td>total</td> <td><?=$_SESSION['total']?></td> </tr> <tr> <td>ส่วนลด 5% เมื่อซื้อครบ 10000 บาท</td> <td><?=$sum1?></td> </tr> <tr> <td>ราคาสุทธิ์</td> <td><?=$sum2?></td> </tr> <tr> <td><a href="user_page.php?id=2">BACK TO PRODUCT</a></td> <td> <input type="submit" name="button" id="button" value="update" /> <input type="button" name="submit2" value="Checkout" onclick="window.location='order3.php';" /> </td> </tr> <? }else { echo "NO CART"; } ?> </table> </form>
<?php $a = 1.5; echo "origin:$a<br />round($a):",round($a),"<br />ceil($a):",ceil($a),"<br />floor($a):",floor($a); ?>
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง