-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.php
More file actions
169 lines (141 loc) · 5.76 KB
/
Copy pathindex.php
File metadata and controls
169 lines (141 loc) · 5.76 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
session_start();
error_reporting(E_ALL);
include('config.php');
$msg = '';
if (isset($_GET['add'])) {
if (isset($_SESSION['user'])) {
$productid = $_GET['add'];
$user = $_SESSION['user'];
$sql = "INSERT INTO cart(productid,user) VALUES(:productid,:user)";
$query = $db->prepare($sql);
$query->bindParam(':productid', $productid, PDO::PARAM_STR);
$query->bindParam(':user', $user, PDO::PARAM_STR);
$query->execute();
$lastInsertId = $db->lastInsertId();
if ($lastInsertId) {
$msg = '<div id="msg" class="alert alert-success"><strong>Product Added To Cart</strong></div>';
} else {
$msg = '<div id="msg" class="alert alert-danger"><strong>Unable To Add</strong></div>';
}
} else {
echo "<script type='text/javascript'> document.location = 'login.php'; </script>";
}
} else {
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TrendZ | Online Store for Latest Trends</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="./css/style.css">
<script>
if (typeof window.history.pushState == 'function') {
window.history.pushState({}, "Hide", '<?php echo $_SERVER['PHP_SELF']; ?>');
}
</script>
</head>
<body>
<section>
<?php include('./inc/header.php'); ?>
<?php include('./inc/carousel.php'); ?>
<div class="container mt-5 my-section">
<h3 class="py-4">Popular Products</h3>
<div class="msg"><?php echo $msg; ?></div>
<div class="row">
<?php
// FECTH PRODUCTS
$sql = "SELECT * from products ORDER BY RAND() LIMIT 4";
$query = $db->prepare($sql);
$query->execute();
$results = $query->fetchAll(PDO::FETCH_OBJ);
if ($query->rowCount() > 0) {
foreach ($results as $result) { ?>
<div class="col-lg-3 col-md-6 mb-4">
<div class="card h-100">
<a href="#"><img class="card-img-top" src="./img/products/<?php echo $result->img; ?>" alt="<?php echo $result->title; ?>" title="<?php echo $result->title; ?>"></a>
<div class="card-body">
<h4 class="card-title">
<a href="#"><?php echo $result->title; ?></a>
</h4>
<h5><?php echo CURRENCY ?> <?php echo $result->price; ?></h5>
<a href="index.php?add=<?php echo $result->id; ?>" class="btn btn-dark mt-2">Add To Cart</a>
</div>
</div>
</div>
<?php }
} ?>
</div>
</div>
<div class="container mt-5 my-section">
<h3 class="py-4">Mens</h3>
<div class="row">
<?php
// FECTH PRODUCTS
$sql = "SELECT * from products WHERE category='Mens' ORDER BY RAND() LIMIT 4";
$query = $db->prepare($sql);
$query->execute();
$results = $query->fetchAll(PDO::FETCH_OBJ);
if ($query->rowCount() > 0) {
foreach ($results as $result) { ?>
<div class="col-lg-3 col-md-6 mb-4">
<div class="card h-100">
<a href="#"><img class="card-img-top" src="./img/products/<?php echo $result->img; ?>" alt="<?php echo $result->title; ?>" title="<?php echo $result->title; ?>"></a>
<div class="card-body">
<h4 class="card-title">
<a href="#"><?php echo $result->title; ?></a>
</h4>
<h5><?php echo CURRENCY ?> <?php echo $result->price; ?></h5>
<a href="index.php?add=<?php echo $result->id; ?>" class="btn btn-dark mt-2">Add To Cart</a>
</div>
</div>
</div>
<?php }
} ?>
</div>
</div>
<div class="container mt-5 my-section">
<h3 class="py-4">Womens</h3>
<div class="row">
<?php
// FECTH PRODUCTS
$sql = "SELECT * from products WHERE category='Women' ORDER BY RAND() LIMIT 4";
$query = $db->prepare($sql);
$query->execute();
$results = $query->fetchAll(PDO::FETCH_OBJ);
if ($query->rowCount() > 0) {
foreach ($results as $result) { ?>
<div class="col-lg-3 col-md-6 mb-4">
<div class="card h-100">
<a href="#"><img class="card-img-top" src="./img/products/<?php echo $result->img; ?>" alt="<?php echo $result->title; ?>" title="<?php echo $result->title; ?>"></a>
<div class="card-body">
<h4 class="card-title">
<a href="#"><?php echo $result->title; ?></a>
</h4>
<h5><?php echo CURRENCY ?> <?php echo $result->price; ?></h5>
<a href="index.php?add=<?php echo $result->id; ?>" class="btn btn-dark mt-2">Add To Cart</a>
</div>
</div>
</div>
<?php }
} ?>
</div>
</div>
<?php include('./inc/footer.php'); ?>
</section>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
setTimeout(function() {
$('#msg').slideUp("slow");
}, 2000);
});
</script>
</body>
</html>