-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayment_success.php
75 lines (63 loc) · 2.06 KB
/
payment_success.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
73
74
75
<?php
session_start();
//if(!isset($_SESSION["userId"])){
//link back to log in page as session is empty
// header("location:signup_mock.php");
//}
if (isset($_GET["st"])){
# code...
$trx_id = $_GET["tx"];
$p_st = $_GET["st"];
$amt = $_GET["amt"];
$cc = $_GET["cc"];
$cm_user_id = $_GET["cm"];
//check if transaction is completed
if ($p_st == "Completed") {
include_once("includes/db.php");
//select all data from cart by the user
$sql = "SELECT `pId`,`quantity` FROM `cart` WHERE `uId` = '$cm_user_id'";
$query = mysqli_query($conn,$sql);
if (mysqli_num_rows($query) > 0) {
# code...
while ($row=mysqli_fetch_array($query)) {
$product_id[] = $row["pId"];
$qty[] = $row["quantity"];
}
//insert data from cart to orders
for($i=0; $i < count($product_id); $i++) {
$sql = "INSERT INTO `orders` (userId,productId,quantity,transactionId,orderStatus) VALUES ('$cm_user_id','".$product_id[$i]."','".$qty[$i]."','$trx_id','$p_st')";
mysqli_query($conn,$sql);
}
//after insertion, drop the data in cart
$sql = "DELETE FROM `cart` WHERE `uId` = '$cm_user_id'";
if (mysqli_query($conn,$sql)) {
?>
<!--html to produce success-->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>eMeal</title>
<link rel="stylesheet" href="css/bootstrap.min.css"/>
<script src="js/jquery2.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="main.js"></script>
</head>
<body>
<div>
<form action="http://localhost/eMeal/shoppinggeneral.php" method="post">
<p>You have successfully paid</p>
<button name="submit" value="submit">Continue shopping</button>
</form>
</div>
</body>
</html>
<?php
}
}else{
//empty data from cart therefore go back to shopping cart
header("location:signup_mock.php?");
}
}
}
?>