-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpurchase.php
121 lines (118 loc) · 3.79 KB
/
purchase.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
session_start();
$_SESSION['err'] = 1;
foreach($_POST as $key => $value){
if(trim($value) == ''){
$_SESSION['err'] = 0;
}
break;
}
if($_SESSION['err'] == 0){
header("Location: checkout.php");
} else {
unset($_SESSION['err']);
}
$_SESSION['ship'] = array();
foreach($_POST as $key => $value){
if($key != "submit"){
$_SESSION['ship'][$key] = $value;
}
}
require_once "./functions/database_functions.php";
// print out header here
$title = "Purchase";
require "./template/header.php";
// connect database
if(isset($_SESSION['cart']) && (array_count_values($_SESSION['cart']))){
?>
<table class="table">
<tr>
<th>Item</th>
<th>Price</th>
<th>Quantity</th>
<th>Total</th>
</tr>
<?php
foreach($_SESSION['cart'] as $isbn => $qty){
$conn = db_connect();
$book = mysqli_fetch_assoc(getBookByIsbn($conn, $isbn));
?>
<tr>
<td><?php echo $book['book_title'] . " by " . $book['book_author']; ?></td>
<td><?php echo "$" . $book['book_price']; ?></td>
<td><?php echo $qty; ?></td>
<td><?php echo "$" . $qty * $book['book_price']; ?></td>
</tr>
<?php } ?>
<tr>
<th> </th>
<th> </th>
<th><?php echo $_SESSION['total_items']; ?></th>
<th><?php echo "$" . $_SESSION['total_price']; ?></th>
</tr>
<tr>
<td>Shipping</td>
<td> </td>
<td> </td>
<td>20.00</td>
</tr>
<tr>
<th>Total Including Shipping</th>
<th> </th>
<th> </th>
<th><?php echo "$" . ($_SESSION['total_price'] + 20); ?></th>
</tr>
</table>
<form method="post" action="process.php" class="form-horizontal">
<?php if(isset($_SESSION['err']) && $_SESSION['err'] == 1){ ?>
<p class="text-danger">All fields have to be filled</p>
<?php } ?>
<div class="form-group">
<label for="card_type" class="col-lg-2 control-label">Type</label>
<div class="col-lg-10">
<select class="form-control" name="card_type">
<option value="VISA">VISA</option>
<option value="MasterCard">MasterCard</option>
<option value="American Express">American Express</option>
</select>
</div>
</div>
<div class="form-group">
<label for="card_number" class="col-lg-2 control-label">Number</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="card_number">
</div>
</div>
<div class="form-group">
<label for="card_PID" class="col-lg-2 control-label">PID</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="card_PID">
</div>
</div>
<div class="form-group">
<label for="card_expire" class="col-lg-2 control-label">Expiry Date</label>
<div class="col-lg-10">
<input type="date" name="card_expire" class="form-control">
</div>
</div>
<div class="form-group">
<label for="card_owner" class="col-lg-2 control-label">Name</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="card_owner">
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="reset" class="btn btn-default">Cancel</button>
<button type="submit" class="btn btn-primary">Purchase</button>
</div>
</div>
</form>
<p class="lead">Please press Purchase to confirm your purchase, or Continue Shopping to add or remove items.</p>
<?php
} else {
echo "<p class=\"text-warning\">Your cart is empty! Please make sure you add some books in it!</p>";
}
if(isset($conn)){ mysqli_close($conn); }
require_once "./template/footer.php";
?>