|
 |
|
หลังจากที่ลูกค้ายืนยันการสั่งซื้อแล้ว อยากจะให้ดูรายการที่ลูกค้าสั่งซื้อได้นะค่ะ รบกวนหน่อยนะค่ะ |
|
 |
|
|
 |
 |
|
นี่เปนโค้ดยืนยันการสั่งซื้อค่ะ มันไม่โชว์ข้อมูลหลังจากที่ลูกค้าสั่งซื้อแล้วนะค่ะ ช่วยหน่อยนะค่ะ
Code (PHP)
<?
session_start();
header("location:finish_order.php?order_id=".$order_id);
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?
include "connect.php";
$name = $_POST["name"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$address = $_POST["address"];
$total = $_POST["total_order"];
if ($name == ""){
echo "<script> alert('กรุณากรอกชือ-สกุล')</script>";
echo "<script>history.back();</script>";
exit();
} else if ($email == "") {
echo "<script> alert('กรุณากรอกอีเมล์')</script>";
echo "<script>history.back();</script>";
exit();
} else if ($phone== ""){
echo "<script> alert('กรุณาเบอร์โทรศัพท์')</script>";
echo "<script>history.back();</script>";
exit();
} else if ($address == "") {
echo "<script> alert('กรุณากรอกที่อยู่')</script>";
echo "<script>history.back();</script>";
exit();
}
$date_now = date("Y-m-d");
$sql1= 'insert into orders '.
'( order_name , order_address , order_email , order_phone , order_total , order_date )'.
" values ( '$name', '$address', '$email', '$phone', '$total', '$date_now')";
// สังเกตครับผมตัด order_id ออก เพราะ ผมคิดว่า field order_id ถูก กำหนดให้เป็น autoincrement
// เมื่อเป็น autoincrement ก็ไม่จำเป็นต้องใส่ค่าครับ
mysql_query($sql1);
$order_id=mysql_insert_id(); // เมื่อ run ใส่บันทัดนี้ต่อเลย
//จะทำให้ ค่าของ $order_id เท่ากับ id ใหม่ที่ถูก กำหนดโดย autoincrement
for($i=0; $i<count($sess_id); $i++) {
$sql3 = 'insert into orders_detail(order_id, product_id, order_number, order_price)'.
" values ('$order_id' , '$sess_id[$i]','$sess_num[$i]', '$sess_price[$i]')" ;
mysql_query($sql3);
}
session_unregister("sess_id");
session_unregister("sess_name");
session_unregister("sess_price");
session_unregister("sess_num");
mysql_close();
?>

Code (PHP)
<html>
<head>
<title>ThaiCreate.Com</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
Finish Your Order. <br><br>
<a href="view_order.php?order_id=<?=$_GET["order_id"];?>">View Order</a>
</body>
</html>

Code (PHP)
<html>
<head>
<title>ThaiCreate.Com</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<?
include "connect.php";
$strSQL = "SELECT * FROM orders WHERE order_id = '".$_GET["order_id"]."' ";
$objQuery = mysql_query($strSQL) or die(mysql_error());
$objResult = mysql_fetch_array($objQuery);
?>
<table width="304" border="1">
<tr>
<td width="71">OrderID</td>
<td width="217">
<?=$objResult["order_id"];?></td>
</tr>
<tr>
<td width="71">Name</td>
<td width="217">
<?=$objResult["order_name"];?></td>
</tr>
<tr>
<td>Address</td>
<td><?=$objResult["order_address"];?></td>
</tr>
<tr>
<td>Tel</td>
<td><?=$objResult["order_phone"];?></td>
</tr>
<tr>
<td>Email</td>
<td><?=$objResult["order_email"];?></td>
</tr>
</table>
<br>
<table width="400" border="1">
<tr>
<td width="101">ProductID</td>
<td width="82">ProductName</td>
<td width="82">Price</td>
<td width="79">Qty</td>
<td width="79">Total</td>
</tr>
<?
$Total = 0;
$SumTotal = 0;
$strSQL2 = "SELECT * FROM orders_detail WHERE order_id = '".$_GET["order_id"]."' ";
$objQuery2 = mysql_query($strSQL2) or die(mysql_error());
while($objResult2 = mysql_fetch_array($objQuery2))
{
$strSQL3 = "SELECT * FROM product WHERE product_id = '".$objResult2["product_id"]."' ";
$objQuery3 = mysql_query($strSQL3) or die(mysql_error());
$objResult3 = mysql_fetch_array($objQuery3);
$Total = $objResult2["order_number"] * $objResult3["order_price"];
$SumTotal = $SumTotal + $Total;
?>
<tr>
<td><?=$objResult2["product_id"];?></td>
<td><?=$objResult3["product_name"];?></td>
<td><?=$objResult3["order_price"];?></td>
<td><?=$objResult2["order_number"];?></td>
<td><?=number_format($Total,2);?></td>
</tr>
<?
}
?>
</table>
Sum Total <?=number_format($SumTotal,2);?>
<?
mysql_close();
?>
</body>
</html>
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2014-07-02 03:30:24 |
By :
zerza18 |
View :
816 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 04
|