<? session_start(); include('config.inc.php'); session_register("cart"); ?> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <? include("config.inc.php"); for ($i=0;$i<count($_SESSION['cart']);$i++) { if($_SESSION["ID_Product"][$i] != "") { $strSQL = "INSERT INTO bill "; $strSQL .="(Price,P_Number2,ID_User,ID_Product) "; $strSQL .="VALUES "; $strSQL .="('".$_SESSION['total']."','".$_SESSION['qty'][$i]."','".$_SESSION["ID_User"]."','".$_SESSION["ID_Product"][$i]."') "; $objQuery = mysql_query($strSQL); } } if($objQuery) { include("config.inc.php"); $total=0; echo '<pre>', print_r($_SESSION['cart'], true), '</pre>'; 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; $strSQL = "Update product Set P_Number = P_Number - '".$_SESSION['qty']."' WHERE ID_Product = '".$_SESSION['ID_Product']."' "; $objQuery = mysql_query($strSQL); } } mysql_close(); echo "<script language=\"JavaScript\" type=\"text/JavaScript\">alert('แก้ไขข้อมูลเรียบร้อยแล้วค่ะ') </script> "; echo"<meta http-equiv='refresh' content='0;url=user_page.php?id=2'>"; exit(); ?>
<? 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']; } } ?> <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; ?> <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><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>
print_r($_SESSION);
print_r($_SESSION['ชื่อ']);
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง