-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.php
65 lines (56 loc) · 1.71 KB
/
process.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
<?php
session_start();
$_SESSION['err'] = 1;
foreach($_POST as $key => $value){
if(trim($value) == ''){
$_SESSION['err'] = 0;
}
break;
}
if($_SESSION['err'] == 0){
header("Location: purchase.php");
} else {
unset($_SESSION['err']);
}
require_once "./functions/database_functions.php";
// print out header here
$title = "Purchase Process";
require "./template/header.php";
// connect database
$conn = db_connect();
extract($_SESSION['ship']);
// validate post section
$card_number = $_POST['card_number'];
$card_PID = $_POST['card_PID'];
$card_expire = strtotime($_POST['card_expire']);
$card_owner = $_POST['card_owner'];
// find customer
$customerid = getCustomerId($name, $address, $city, $zip_code, $country);
if($customerid == null) {
// insert customer into database and return customerid
$customerid = setCustomerId($name, $address, $city, $zip_code, $country);
}
$date = date("Y-m-d H:i:s");
insertIntoOrder($conn, $customerid, $_SESSION['total_price'], $date, $name, $address, $city, $zip_code, $country);
// take orderid from order to insert order items
$orderid = getOrderId($conn, $customerid);
foreach($_SESSION['cart'] as $isbn => $qty){
$bookprice = getbookprice($isbn);
$query = "INSERT INTO order_items VALUES
('$orderid', '$isbn', '$bookprice', '$qty')";
$result = mysqli_query($conn, $query);
if(!$result){
echo "Insert value false!" . mysqli_error($conn2);
exit;
}
}
session_unset();
?>
<p class="lead text-success">Your order has been processed sucessfully. Please check your email to get your order confirmation and shipping detail!.
Your cart has been empty.</p>
<?php
if(isset($conn)){
mysqli_close($conn);
}
require_once "./template/footer.php";
?>