-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-result.php
72 lines (63 loc) · 2.5 KB
/
update-result.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
include_once('config.php');
session_save_path('./session');
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
</head>
<body>
<?php
if(isset($_SESSION['access']) && $_SESSION['access']==true) {
$order_id=$_POST['oid'];
$product_id=$_POST['pid'];
$product_num=$_POST['num'];
if( intval($product_num) === 0){
$stmt = mysqli_prepare($con,"DELETE FROM `Subscribe` WHERE `orderID` = ? AND `productID` = ?");
mysqli_stmt_bind_param($stmt,'si',$order_id, $product_id);
$upd_1=mysqli_stmt_execute($stmt);
}
else{
$stmt = mysqli_prepare($con,"UPDATE `Subscribe` SET `productNum` = ? WHERE `orderID` = ? AND `productID` = ?");
mysqli_stmt_bind_param($stmt,'isi',$product_num, $order_id, $product_id);
$upd_1=mysqli_stmt_execute($stmt);
}
//calculate totalCost
$stmt = mysqli_prepare($con,"SELECT `productNum`,`productCost` FROM `Subscribe` NATURAL JOIN `Product` WHERE `orderID` = ?");
mysqli_stmt_bind_param($stmt,'s',$order_id);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
mysqli_stmt_bind_result($stmt, $res_pruductNum, $res_productCost);
$total_cost = 0;
while(mysqli_stmt_fetch($stmt)) {
$total_cost += $res_pruductNum*$res_productCost;
}
//END calculate totalCost
$stmt = mysqli_prepare($con,"UPDATE `Order` SET `totalCost` = ? WHERE `orderID` = ? ");
mysqli_stmt_bind_param($stmt,'ss',$total_cost, $order_id);
$upd_2=mysqli_stmt_execute($stmt);
if($upd_1 && $upd_2){
echo "<div class='alert alert-success'> Update!</div>";
} else {
echo "<div class='alert alert-info'> Update! Fail! </div>";
}
mysqli_stmt_close($stmt);
mysqli_close($con);
header("Refresh: 1; url=update.php?id=".$order_id);
}
else{
echo "<html>
<head>
<title>Error</title>
<link href='css/bootstrap.min.css' rel='stylesheet' media='screen'>
</head>
<body><div class='alert alert-error'> <h1>You shall not pass!</h1></div></body></html>";
mysqli_close($con);
header('Refresh: 3; url=index.php');
}
?>
</body>
</html>