-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcart.php
More file actions
146 lines (123 loc) · 6.49 KB
/
cart.php
File metadata and controls
146 lines (123 loc) · 6.49 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<?php
include "./includes/header.php"
?>
</head>
<body>
<?php
include "./includes/nav.php"
?>
<script src="https://js.stripe.com/v3/"></script>
<link rel="stylesheet" href="./css/stripe.css">
<div class="cart-container">
<br>
<br>
<div class="page-header">
<div class="data">
<h1 id="cartheading">Your Order</h1>
<h2 id="pricing">$0 SGD</h2>
</div>
<!-- hide the button if thcart is empty-->
</div>
<div class="cart">
<?php
session_start();
if (isset($_SESSION['memberid'])) {
$memberid = $_SESSION['memberid'];
} else {
header("Location: ./login.php?rd=cart"); //header wont work because bootstrap is bad bad
echo "<meta http-equiv='refresh' content='0;url=./login.php?rd=cart'>";
return;
}
$config = parse_ini_file('../../private/db-config.ini');
$conn = new mysqli($config['servername'], $config['username'], $config['password'], "project1004");
if ($conn->connect_error) {
$errorMsg = "Connection failed: " . $conn->connect_error;
echo $errorMsg;
$success = false;
} else {
$stmt = $conn->prepare("SELECT *, cart.id as cartid from cart inner join car ON cart.car_id = car.id where member_id = ?");
//int id, varchar catID, varchar brand, varchar heading, float price, int stock, bool forRent, varchar model,text description,varchar bigImage,varchar logo, int isMain
$stmt->bind_param("i", $memberid);
$stmt->execute();
$result = $stmt->get_result();
$totalprice = 0;
//echo $result->num_rows;
if ($result->num_rows > 0) {
//$row = $result->fetch_assoc();
while ($row = $result->fetch_assoc()) {
$carid = $row['car_id'];
$cartid = $row['cartid'];
$display = $row["media"];
$qty = $row['qty'];
$logo = $row["brand"] . ".png";
$itemname = strtoupper($row["brand"]) . " " . $row["model"];
$price = money_format('%.2n', $row["price"]);
$totalprice += $row["price"];
$stock = $row['stock'];
?>
<div class="cart-data">
<img class="display" src="./images/hd/<?php echo $display ?>"/>
<img class="small-logo" src="./images/logos/<?php echo $logo ?>"/>
<p class="item-name"><?php echo $itemname ?></p>
<input type="text" name="cartid" value="<?php echo $cartid; ?>" hidden>
<div class="item-data">
<p>$<?php echo $price ?></p>
<p>Quantity: <?php echo $qty ?></p>
<div class="update-delete">
<form action="updatecart.php" method="post">
<label><p>New Quantity:</p></label>
<select id="qty" name="qty">
<?php
for ($x = 1; $x <= $stock; $x++) {
echo '<option value="' . $x . '">' . $x . '</option>';
}
?>
</select>
<input class="updatebutton" type="submit" value="Update">
<input type="text" name="cartid" value="<?php echo $cartid; ?>"hidden>
</form>
</div>
<form action="deleteitem.php" method="post">
<input class="deletebutton" type="submit" value="Delete">
<input type="text" name="cartid" value="<?php echo $cartid; ?>" hidden>
</form>
</div>
</div>
<?php
}
echo "<script>document.getElementById('pricing').innerHTML = '" . money_format('%.2n', $totalprice) . "';</script>";
} else {
echo "<script>document.getElementById('cartheading').innerHTML = 'No items. Add more!';</script>";
}
if ($result->num_rows < 5) {
$extra = 5 - $result->num_rows;
for ($i = 0; $i < $extra; $i++) {
?>
<div class="cart-data">
<a href="./">
<img class="display" src="./images/hd/background.jpg"/>
<img class="smaller-logo" src="./images/logos/plus.png"/>
<p class="item-name light-accent">Continue Shopping!</p>
<div class="item-data">
<p></p>
</div>
</a>
</div>
<?php
}
}
?>
<button id="cobutton" onclick="window.location.href = './checkout.php'" class="cobutton">Checkout</button>
<?php }
?>
</div>
</div>
<?php
include "./includes/footer.php";
?>
</body>
</html>