-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkout.php
91 lines (90 loc) · 2.82 KB
/
checkout.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
<?php
// the shopping cart needs sessions, to start one
/*
Array of session(
cart => array (
book_isbn (get from $_GET['book_isbn']) => number of books
),
items => 0,
total_price => '0.00'
)
*/
session_start();
require_once "./functions/database_functions.php";
// print out header here
$title = "Checking out";
require "./template/header.php";
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>
</table>
<form method="post" action="purchase.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="name" class="control-label col-md-4">Name</label>
<div class="col-md-4">
<input type="text" name="name" class="col-md-4" class="form-control">
</div>
</div>
<div class="form-group">
<label for="address" class="control-label col-md-4">Address</label>
<div class="col-md-4">
<input type="text" name="address" class="col-md-4" class="form-control">
</div>
</div>
<div class="form-group">
<label for="city" class="control-label col-md-4">City</label>
<div class="col-md-4">
<input type="text" name="city" class="col-md-4" class="form-control">
</div>
</div>
<div class="form-group">
<label for="zip_code" class="control-label col-md-4">Zip Code</label>
<div class="col-md-4">
<input type="text" name="zip_code" class="col-md-4" class="form-control">
</div>
</div>
<div class="form-group">
<label for="country" class="control-label col-md-4">Country</label>
<div class="col-md-4">
<input type="text" name="country" class="col-md-4" class="form-control">
</div>
</div>
<div class="form-group">
<input type="submit" name="submit" value="Purchase" class="btn btn-primary">
</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";
?>