-
Notifications
You must be signed in to change notification settings - Fork 3
/
checkout.php
58 lines (57 loc) · 1.71 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
<?php
session_start();
require_once "./functions/database_functions.php";
// print out header here
$title = "Checking out";
require "./template/header.php";
if(!isset($_SESSION['user'])){
echo '<div class="alert alert-danger" role="alert">
You Need to <a href="Signin.php">Signin</a> First!
</div>';
}
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>
<?php
if(isset($_SESSION['user'])){
echo '<form method="post" action="purchase.php" class="form-horizontal">
<div class="form-group" style="margin-left:0px">
<input type="submit" name="submit" value="Purchase" class="btn btn-primary" >
<a href="cart.php" class="btn btn-primary">Edit Cart</a>
</div>
</form>
<p class="lead">Please press Purchase to confirm your purchase, or Edit Cart 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";
?>