-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdisplayProducts.php
140 lines (99 loc) · 2.77 KB
/
displayProducts.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
132
133
134
135
136
137
138
139
140
<?php
//session_start();
require_once("dbconnect.php");
if(isset($_GET['page'])){
$pages = array("products", "cart");
if(in_array($_GET['page'], $pages)) {
$_page = $_GET['page'];
}else{
$_page="products";
}
}else{
$_page="products";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="../css/reset.css" />
<style>
#container {
width: 100%;
margin: auto;
background-color: #eee;
overflow: hidden; /* Set overflow: hidden to clear the floats on #main and #sidebar */
padding: 15px;
}
#main {
width: 520px;
float: left;
}
#sidebar {
width: 350px;
float: left;
}
a {color: #48577D; text-decoration: none;}
a:hover {text-decoration: underline;}
h1, h2 {margin-bottom: 15px}
h1 {font-size: 18px;}
h2 {font-size: 16px}
#main table {
width: 480px;
}
#main table th {
padding: 10px;
background-color: #48577D;
color: #fff;
text-align: left;
}
#main table td {
padding: 5px;
}
#main table tr {
background-color: #d3dcf2;
}
</style>
<title>Shopping cart</title>
</head>
<body>
<div id="container">
<div id="main">
<?php require($_page.".php"); ?>
<?php //require($_page.".php"); ?>
</div><!--end main-->
<div id="sidebar">
<h1>Cart</h1>
<?php
if(isset($_SESSION['cart'])){
$conn= mysqli_connect("localhost", "root", "", "compsys");
$sql="SELECT * FROM stock WHERE stock_id IN (";
foreach($_SESSION['cart'] as $id => $value) {
$sql .= $id .",";
}
//echo strlen($sql);
//$sql[39] = ' '; // getting rid of the first comma
$sql = substr($sql, 0, -1) .") ORDER BY stock_id ASC";
$res = mysqli_query($conn, $sql);
if (!$res) {
printf("<h2>Basket is empty.</h2> %s", "<br><strong>Please choose your products from the left!<strong>"); //mysqli_error($conn)
exit();
}
while($row=mysqli_fetch_array($res)){
?>
<p><?php echo $row['description'] ?> x <?php echo $_SESSION['cart'][$row['stock_id']]['quantity'] ?></p>
<?php
}
?>
<hr />
<a href="chooseProducts.php?page=cart">Go to cart</a>
<?php
}else{
echo "<p>Your Cart is empty. Please add some products.</p>";
}
?>
</div><!--end sidebar-->
</div><!--end container-->
</body>
</html>