|
|
|
เกี่ยวกับ code ตะกร้าสินค้าครับ ต้องการให้สั่งซื้อสินค้าเสร็จแล้วให้มัน refresh ตะกร้าสินค้าคับ ไม่ให้มันจำ session ตัวเดิม |
|
|
|
|
|
|
|
** ต้องการสั่งซื้อสินค้าเสร็จแล้วคับ ให้มันรีเฟดตะกร้า เมื่อกดดูตะกร้าสินค้าจะวางเปล่า**
**คือระบบผมต้องสมัครสมาชิก ตะกร้าสินค้าจะว่างเปล่าก็ต่อเมื่อ logout อย่างเดียวคับ**
code หน้าเก็บตระกร้าคับ
Code (PHP)
<?
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>
code หน้ายืนยันคับ
Code (PHP)
<?
session_start();
include('config.inc.php');
session_register("cart");
?>
<form id="cart1" name="cart1" method="post" action="process.php">
<table align="center" class="square" width="600" border="1">
<tr>
<td width="1400">สั่งซื้อสินค้า</td>
</tr>
<tr>
<tr>
<td>Product</td>
<td width="117">Price</td>
<td width="25">Unit</td>
<td width="42">include</td>
</tr>
<?
$total=0;
foreach($_SESSION['cart'] as $ID_Product=>$qty)
{
$sql = "SELECT * FROM product where ID_Product=$ID_Product";
$query = mysql_query($sql) or die ("error=$sql");
$objResult = mysql_fetch_array($query);
$sum = $objResult['P_Price']*$qty;
$total += $sum;
if($_SESSION['total']>=10000)
{
$sum1 = $_SESSION['total']*0.05;
$_SESSION['sum2'] = $_SESSION['total'] - $sum1;
}
?>
<tr>
<td width="334"><?=$objResult["P_name"]?></td>
<td width="46" align="right"><?=$objResult["P_Price"]?></td>
<td width="57" align="right"><?=$qty?></td>
<td width="93" align="right"><?=$sum?></td>
</tr>
<?
}
?>
<tr>
<td>total</td>
<td><?=$total?></td>
</tr>
<tr>
<td>ส่วนลด 5% เมื่อซื้อครบ 10000 บาท</td>
<td><?=$sum1?></td>
</tr>
<tr>
<td>ราคาสุทธิ์</td>
<td><?=$_SESSION['sum2']?></td>
</tr>
<tr>
<td align="center" bgcolor="#cccccc" >
<input type="submit" name="submit2" value="ยืนยัน" onclick="return confirm('ยืนยันการสั่งสินค้า')" />
</td>
</tr>
</table>
</form>
code หน้าคำนวนคับ
Code (PHP)
<?
session_start();
include('config.inc.php');
session_register("cart");
date_default_timezone_set("Asia/Bangkok");
include("config.inc.php");
foreach($_SESSION['cart'] as $_SESSION['ID_Product']=>$_SESSION['qty'])
{
$strSQL = "INSERT INTO bill2 ";
$strSQL .="(OrderDate,ID_User,Price,discount) ";
$strSQL .="VALUES ";
$strSQL .="('".date("Y-m-d H:i:s")."','".$_SESSION["ID_User"]."','".$_SESSION['total']."','".$_SESSION['sum2']."') ";
$objQuery = mysql_query($strSQL);
}
$strID_Buy = mysql_insert_id();
foreach($_SESSION['cart'] as $_SESSION['ID_Product']=>$_SESSION['qty'])
{
$strSQL = "INSERT INTO bill ";
$strSQL .="(P_Number2,ID_Product,ID_Buy) ";
$strSQL .="VALUES ";
$strSQL .="('".$_SESSION['qty']."','".$_SESSION["ID_Product"]."','".$strID_Buy."') ";
$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'][$i]."' ";
$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;
$_SESSION['sum2'] = $_SESSION['total'] - $sum1;
}
$strSQL = "Update product Set P_Number = P_Number - '".$_SESSION['qty']."' WHERE ID_Product = '".$_SESSION['ID_Product']."' ";
$objQuery = mysql_query($strSQL);
}
}
mysql_close();
header("location:finish_order2.php?ID_Buy=".$strID_Buy);
/*echo "<script language=\"JavaScript\" type=\"text/JavaScript\">alert('สั่งซื้อสินค้าเรียบร้อยแล้วครับ') </script> ";
echo"<meta http-equiv='refresh' content='0;url=finish_order.php?ID_Buy='.$strID_Buy>";
exit(); */
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
code หน้าปริ้นใบเส็จคับ
Code (PHP)
<font color="#FF0000" size="4">สั่งซื้อสินค้าเสร็จสิ้นแล้ว</font><br><br><br>
<a href="show_id_buy2.php?ID_Buy=<?=$_GET["ID_Buy"];?>"><img src="img/print.png" width="50" height="50" /><font color="#000000" size="3">พิมพ์ใบเสร็จสั่งซื้อ</font></a>
Tag : PHP, MySQL
|
ประวัติการแก้ไข 2013-08-13 02:10:36
|
|
|
|
|
Date :
2013-08-13 02:05:52 |
By :
woraman |
View :
1078 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้ลองดูพวกการ Clear Session แล้วหรือยังครับ
|
|
|
|
|
Date :
2013-08-13 08:43:45 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
session_destroy();
PHP Session
|
|
|
|
|
Date :
2013-08-13 16:44:36 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|