FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
T2-Web-Programming/cart.php at main · MilkyWay2k/T2-Web-Programming · GitHub
MilkyWay2k
/
T2-Web-Programming
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
T2-Web-Programming
/
cart.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
188 lines (167 loc) · 6.27 KB
Breadcrumbs
T2-Web-Programming
/
cart.php
Copy path
File metadata and controls
188 lines (167 loc) · 6.27 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
session_start
();
session_id
();
$
title
=
"
Skate Shop - Cart
"
;
$
stylesheet
=
"
cart
"
;
$
extra
=
""
;
include
"
partials/header.php
"
;
$
cart_id
=
session_id
();
include
"
partials/db.php
"
;
//$sql = "SELECT cart_item.product_id, product.product_name, product.price FROM cart_item INNER JOIN product ON cart_item.product_id = product.product_id";
/*$sql = "SELECT SUM(cart_item.quantity), products.product_name, products.price
FROM cart_item
JOIN products ON cart_item.product_id = products.product_id
WHERE cart_item.session_id = '$cart_id'
GROUP BY cart_item.product_id;
";
*/
$
sql
=
"
SELECT products.product_name, SUM(cart_item.quantity) AS quantity, MIN(products.price)*SUM(cart_item.quantity) AS total_price
FROM cart_item INNER JOIN products ON cart_item.product_id = products.product_id
GROUP BY products.product_name;
"
;
$
result
=
$
conn
->
query
(
$
sql
);
mysqli_select_db
(
$
conn
,
'
cart_item
'
);
$
sql_cart
=
"
SELECT * FROM cart_item
"
;
$
result_cart
=
$
conn
->
query
(
$
sql_cart
);
?>
<div class="container">
<div class="row breadcrumbs">
<div class="col-12">
<a href="index.php">Main page</a>
<img src="images/Icons/ArrowRight.png">
<a href="shop.php">Shop</a>
<img src="images/Icons/ArrowRight.png">
<b>Cart</b>
</div>
<div class="row justify-content-center">
<div class="col-md-6 justify-content-center" style="margin-bottom: 10px;">
<img src="images/Product2.png" class="thumbnail">
</div>
<div class="col-md-6">
<div class="prices">
<?php
if
(
$
result
->
num_rows
>
0
) {
while
(
$
row
=
$
result
->
fetch_assoc
()){
?>
<div class="title">
<?php
echo
$
row
[
'
quantity
'
];
?>
x</div>
<div class="title">
<?php
echo
$
row
[
'
product_name
'
];
?>
</div>
<div class="amount">
<?php
echo
$
row
[
'
total_price
'
];
?>
€</div>
<br>
<?php
}
}
else
{
echo
"
<p>your cart is empty.</p>
"
;
}
?>
<div class="title">Shipping</div>
<div class="amount">5€</div>
<div class="total">
<hr>
<div class="title"><b>Total</b></div>
<div class="amount">
<?php
$
sql
=
"
SELECT SUM(total_price)+5 AS total
FROM (
SELECT (MIN(products.price)*SUM(cart_item.quantity)) AS total_price
FROM cart_item INNER JOIN products ON cart_item.product_id = products.product_id
GROUP BY products.product_name
) AS yes
"
;
$
result
=
$
conn
->
query
(
$
sql
);
if
(
$
result
->
num_rows
>
0
) {
while
(
$
row
=
$
result
->
fetch_assoc
()){
echo
$
row
[
'
total
'
];
}
}
else
{
echo
"
<p>your cart is empty.</p>
"
;
}
?>
€</div>
<?php
?>
<br>
<br>
</div>
</div>
</div>
</div>
</div>
<hr>
<h4>Contact information</h4>
<div class="row justify-content-center">
<div class="col-md-6 justify-content-center text-center" style="margin-bottom: 20px;">
<form method="post" name="cartForm">
<input type="text" id="fname" name="fname" placeholder="First name"> <br>
<input type="text" id="lname" name="lname" placeholder="Last name"><br>
<input type="text" id="email" name="email" placeholder="Email"><br>
<div class="box">
<input type="checkbox" id="signup" name="signup" checked>
</div>
<div class="box-text">Email me with news and offers</div><br>
<div class="box">
<input type="radio" id="pickup" name="deliveryOption" value="pickup">
</div>
<div class="box-text">Pick up</div>
<div class="box">
<input type="radio" id="delivery" name="deliveryOption" value="delivery">
</div>
<div class="box-text">Delivery</div>
</div>
<div class="col-md-6 justify-content-center text-center">
<select id="country" name="country">
<option value="finland">Finland</option>
<option value="australia">Australia</option>
<option value="canada">Canada</option>
<option value="usa">USA</option>
<option value="nk">North Korea</option>
<option value="madagascar">Madagascar</option>
<option value="vatican">Vatican city</option>
</select><br>
<input type="text" id="company" name="company" placeholder="Company (Optional)"><br>
<input type="text" id="address" name="address" placeholder="Address"><br>
<input type="text" id="postal code" name="postalCode" placeholder="Postal code"
style="width: 40%; margin-right: 10%;">
<input type="text" id="city" name="city" placeholder="City" style="width: 40%;"><br>
<input type="text" id="phone" name="phone" placeholder="Phone"><br>
<div class="box">
<input type="checkbox" id="save" name="save">
</div>
<div class="box-text">Save this infomation for next time</div>
</div>
</div>
<div class="row justify-content-between">
<div class="col-sm-6" style="margin-bottom: 25px; width: 200px;">
<a href="shop.php">
<img src="images/Icons/ArrowLeft.png" alt="Left arrow">
Return to shop
</a>
</div>
<div class="col-sm-6">
<div class="button-link">
<input type="submit" value="Continue to payment" name="submit" class="continue-button"
style="padding-top: 0px;" onclick="return valCart()">
</form>
</div>
</div>
</div>
</div>
<script src="js/val1.js"></script>
<?php
if
(
isset
(
$
_POST
[
"
submit
"
])) {
$
fname
=
$
_POST
[
"
fname
"
];
$
lname
=
$
_POST
[
"
lname
"
];
$
email
=
$
_POST
[
"
email
"
];
$
delivery
=
$
_POST
[
"
deliveryOption
"
];
$
address
=
$
_POST
[
"
address
"
];
$
postalCode
=
$
_POST
[
"
postalCode
"
];
$
city
=
$
_POST
[
"
city
"
];
$
phone
=
$
_POST
[
"
phone
"
];
$
company
=
$
_POST
[
"
company
"
];
$
sql
=
"
insert into product_purchase (fname, lname, email, delivery, address, postalCode, city, phone, company)
values('
$
fname
', '
$
lname
', '
$
email
', '
$
delivery
', '
$
address
', '
$
postalCode
', '
$
city
', '
$
phone
', '
$
company
')
"
;
if
(
$
conn
->
query
(
$
sql
)) {
//echo "<script type=\"text/javascript\">toPayment();</script>";
}
else
{
echo
"
Error 😥:
"
.
$
conn
->
error
;
}
}
include
'
partials/footer.php
'
;
?>
Back
|
FazBrowse Home
|
New Git URL