-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcart.php
131 lines (128 loc) · 3.14 KB
/
cart.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
122
123
124
125
126
127
128
129
130
131
<?php
session_start();
error_reporting(E_ERROR | E_PARSE);
//connect to database
$mysqli = mysqli_connect("localhost", "root", "", "test");
$display_block = "<h1>Your Shopping Cart</h1>";
//check for cart items based on user session id
$get_cart_sql = "SELECT st.id, si.item_title, si.item_price,
st.sel_item_qty FROM
store_shoppertrack AS st LEFT JOIN store_items AS si ON
si.id = st.sel_item_id WHERE username =
'".$_SESSION['username']."'";
$get_cart_res = mysqli_query($mysqli, $get_cart_sql)
or die(mysqli_error($mysqli));
if (mysqli_num_rows($get_cart_res) < 1) {
//print message
$display_block .= "<p>You have no items in your cart.
Please <a href=\"home.php\">continue to shop</a>!</p>";
} else {
//get info and build cart display
$display_block .= <<<END_OF_TEXT
<table>
<tr>
<th>Title</th>
<th>Price</th>
<th>Qty</th>
<th>Total Price</th>
<th>Action</th>
</tr>
END_OF_TEXT;
while ($cart_info = mysqli_fetch_array($get_cart_res)) {
$id = $cart_info['id'];
$item_title = stripslashes($cart_info['item_title']);
$item_price = $cart_info['item_price'];
$item_qty = $cart_info['sel_item_qty'];
$total_price = sprintf("%.02f", $item_price * $item_qty);
$display_block .= <<<END_OF_TEXT
<tr>
<td>$item_title <br></td>
<td>\$ $item_price <br></td>
<td>$item_qty <br></td>
<td>\$ $total_price</td>
<td><a href="removefromcart.php?id=$id">remove</a></td>
</tr>
END_OF_TEXT;
}
$display_block .= "</table>";
}
//free result
mysqli_free_result($get_cart_res);
//close connection to MySQL
mysqli_close($mysqli);
?>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<style>
* {
box-sizing: border-box;
}
body {
display: flex;
min-height: 100vh;
flex-direction: row;
margin: 0;
}
.col-1 {
background: rgb(190, 190, 190);
}
.col-2 {
display: flex;
flex-direction: column;
flex: 5;
}
.content {
display: flex;
flex-direction: row;
}
.content > article {
flex: 4;
min-height: 60vh;
}
header, footer {
background: rgb(190, 190, 190);
height: 10vh;
}
header, footer, article, nav {
padding: 1em;
}
p {color:black;}
</style>
<html>
<head>
<title>CIST 2550 Final</title>
</head>
<nav class="col-1"><img src="NorthGeorgiaTech.jpg" alt"ngtc" style="width:250px;height:125px;"></img>
<ul>
<li><a href="home.php">Home</a></li>
<li><a href="cart.php">Cart</a></li>
<li><a href="contactus.html">Contact Us</a>
<li><a href="showcalendar_withevent.php">Show calendar</a></li>
<li><a href="login.php">Account</a></li>
</ul>
</nav>
<div class="col-2">
<header></header>
<style type="text/css">
table {
border: 1px solid black;
border-collapse: collapse;
}
th {
border: 1px solid black;
padding: 6px;
font-weight: bold;
background: #ccc;
text-align: center;
}
td {
border: 1px solid black;
padding: 6px;
vertical-align: top;
text-align: center;
}
</style>
</head>
<body>
<?php echo $display_block; ?>
</body>
</html>