|
|
|
ช่วยดูให้ทีครับ มัน ไม่ยอม insert ข้อมูลลง order_detail ให้อะครับ |
|
|
|
|
|
|
|
Code (PHP)
<?
include("include/connection.php");
include ("include/function.php");
include ("chk_session.php");
$sql = "
SELECT *
FROM customer
WHERE customer_id = '$sess_userid'
";
$result = mysql_query($sql) or die ( mysql_error() );
$data = mysql_fetch_array( $result );
if(!empty($data['customer_address'])){
$address = $data['customer_address'];
}else{
echo "<script>alert('Please input your address!');window.location = 'member_profile.php';</script>";
exit();
}
if(empty($data['customer_address'])){
echo "<script>alert('Please input your Telephone!');window.location = 'member_profile.php';</script>";
}
$sql = "
SELECT SUM( basket_quantity * product_price )-SUM(basket_quantity*product_sale) 'sum_basket'
FROM basket
INNER JOIN product ON basket.product_id = product.product_id
WHERE customer_id = '$sess_userid'
";
$result = mysql_query($sql) or die( mysql_error() );
$data = mysql_fetch_array($result);
$sum = $data['sum_basket']+$pricetran+$pricepay;
/*
echo $sum."<br/>";
*/
$date=date("Y-m-d H:i:s");
$credit = 7;
$shipdate = date("Y-m-d H:i:s", strtotime("+" . $credit . " day", strtotime($date)));
/*
echo $date."<br/>";
echo $shipdate."<br/>";
*/
$sql = "
INSERT INTO orders
( customer_id,transport_id,payment_id, orders_date, orders_deadline, orders_price, orders_address, orders_status )
VALUES
('$sess_userid','$typetran','$typepay','$date','$shipdate','$sum','$address','No')
";
mysql_query($sql) or die( mysql_error() );
$order = mysql_insert_id();
$sql = "
SELECT basket.product_id,product_price,product_discount,product_sale,basket_quantity
FROM basket
INNER JOIN product ON basket.product_id = product.product_id
WHERE customer_id = '$sess_userid'
";
$result = mysql_query($sql) or die( mysql_error() );
while($data = mysql_fetch_array($result) ){
$id=$data['product_id'];
$price=$data['product_price'];
$discount=$data['product_discount'];
$sale=$data['product_sale'];
$quantity=$data['basket_quantity'];
$sql = "
INSERT INTO orders_detail(
orders_id,
product_id,
orders_detail_product_price,
orders_detail_product_discount,
orders_detail_product_sale,
orders_detail_quantity,
)
VALUES
('$order','$id','$price','$discount','$sale','$quantity')
";
$sql = "
UPDATE product
SET
product_quantity = product_quantity - '$quantity'
WHERE product_id = '$id'
";
mysql_query($sql) or die( mysql_error() );
}
$sql = "
DELETE
FROM basket
WHERE customer_id = '$sess_userid'
";
mysql_query($sql) or die( mysql_error() );
?>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2011-03-06 21:30:14 |
By :
rakmomteesud |
View :
811 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "
INSERT INTO orders_detail(
orders_id,
product_id,
orders_detail_product_price,
orders_detail_product_discount,
orders_detail_product_sale,
orders_detail_quantity,
)
VALUES
('$order','$id','$price','$discount','$sale','$quantity')
";
|
|
|
|
|
Date :
2011-03-07 01:56:36 |
By :
PlaKriM |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ชอบคุณมากครับ ได้ล่ะครับ
|
|
|
|
|
Date :
2011-03-07 03:48:21 |
By :
rakmomteesud |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|