-
Notifications
You must be signed in to change notification settings - Fork 1
/
search.php
339 lines (282 loc) · 10.5 KB
/
search.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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<?php
session_start();
?>
<!DOCTYPE HTML>
<html>
<head>
<title>FullCashback - Get Up To 100% Cashback on Amazon Products!</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<style>
.bd-placeholder-img {
font-size: 1.125rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}
@media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5rem;
}
}
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content/Box */
.modal-content {
background-color: #fefefe;
margin: 15% auto; /* 15% from the top and centered */
padding: 20px;
border: 1px solid #888;
width: 80%; /* Could be more or less, depending on screen size */
}
/* The Close Button */
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
</style>
</head>
<body>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$emailErr = $passwordErr = $paypalErr = "";
$email = $password = $paypalusername = "";
if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}
if (empty($_POST["password"])) {
$passwordErr = "Password is required";
} else {
$password = test_input($_POST["password"]);
}
$paypalusername = test_input($_POST["paypalusername"]);
if ($emailErr == "" && $passwordErr == "") {
$currentemail = $_COOKIE['email'];
//$email = $_POST['email'];
//$password = $_POST['password'];
//$paypalusername = $_POST['paypalusername'];
// Create connection
$conn = mysqli_connect("localhost", "root", "PASSWORD", "fullcashback");
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "UPDATE users SET email='$email', password='$password', paypalusername='$paypalusername' WHERE email='$currentemail'";
if (mysqli_query($conn, $sql)) {
echo "Account details updated successfully";
} else {
echo "Error updating record: " . mysqli_error($conn);
}
mysqli_close($conn);
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<?php
if (isset($_COOKIE['email'])) {
$email = $_COOKIE['email'];
$db = new PDO("mysql:host=localhost;dbname=fullcashback","root","PASSWORD");
$articlesor = $db->prepare("SELECT * FROM users WHERE email=:email");
$articlesor->execute(array(
'email' => $email
));
while($articlecek=$articlesor->fetch(PDO::FETCH_ASSOC)) {
?>
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<div class="card-body">
<h1>Edit Your Account Details</h1>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" class="p-4 p-md-5 border rounded-3 bg-light">
<div class="form-floating mb-3">
<input type="email" name="email" value="<?php echo $articlecek['email'];?>" class="form-control" id="floatingInput" placeholder="[email protected]">
<label for="floatingInput">Email address</label>
<span style="color:red;"><?php echo $emailErr;?></span>
</div>
<div class="form-floating mb-3">
<input type="password" name="password" value="<?php echo $articlecek['password'];?>" class="form-control" id="floatingPassword" placeholder="Password">
<label for="floatingPassword">Password</label>
<span style="color:red;"><?php echo $passwordErr;?></span>
</div>
<div class="form-floating mb-3">
<input type="text" name="paypalusername" value="<?php echo $articlecek['paypalusername'];?>" class="form-control" id="floatingInput" placeholder="PayPal Username">
<label for="floatingPassword">PayPal Username</label>
<span style="color:red;"><?php echo $paypalErr;?></span>
</div>
<div class="form-floating mb-3 input-group">
<input type="text" disabled name="emailverified" value="<?php echo $articlecek['emailverified'];?>" class="form-control" id="floatingInput" placeholder="Email Verified">
<label for="floatingPassword">Email Verified</label>
<?php
if ($articlecek['emailverified'] == "false") {
?>
<a href="send-email.php?email=<?php echo $articlecek['email'] ?>"><button class="btn btn-outline-secondary">Verify Email</button></a><br>
<?php } ?>
</div>
<span style="color:red;"><?php echo $emailVerifiedErr;?></span>
<button class="w-100 btn btn-lg btn-primary" type="submit">Save Changes</button>
</form>
</div>
</div>
</div>
<?php
}
}
?>
<header class="p-3 mb-3 border-bottom">
<div class="container">
<div class="d-flex flex-wrap align-items-center justify-content-center justify-content-lg-start">
<a href="/" class="d-flex align-items-center mb-2 mb-lg-0 text-dark text-decoration-none">
<svg class="bi me-2" width="40" height="32" role="img" aria-label="Bootstrap"><use xlink:href="#bootstrap"></use></svg>
</a>
<ul class="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
<li><a href="index.php" class="nav-link px-2 link-secondary">Home</a></li>
<li><a href="home.php" class="nav-link px-2 link-dark">Products</a></li>
</ul>
<form method="GET" action="search.php" class="col-12 col-lg-auto mb-3 mb-lg-0 me-lg-3">
<input name="name" type="search" class="form-control" placeholder="Search..." aria-label="Search">
</form>
<?php
if (isset($_COOKIE['email'])) {
?>
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
<?php echo $_COOKIE['email']; ?>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
<li><a class="dropdown-item" onclick="deleteCookie();">Log Out</a></li>
<li><a class="dropdown-item" id="showModal">Edit Account Details</a></li>
<li><a class="dropdown-item" href="applications.php">Product Applications</a></li>
<li><a class="dropdown-item" href="payments.php">Payments</a></li>
</ul>
</div>
<?php } ?>
</div>
</div>
</header>
<main>
<section class="py-5 text-center container">
<div class="row py-lg-5">
<div class="col-lg-6 col-md-8 mx-auto">
<h1 class="fw-light">Search</h1>
<h3><?php echo($_GET['name']); ?></h3>
<br>
</div>
</div>
</section>
<div class="album py-5 bg-light">
<div class="container">
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 g-3">
<?php
$productname = $_GET['name'];
//$db = new PDO("mysql:host=localhost;dbname=fullcashback","root","PASSWORD");
//$articlesor = $db->prepare("SELECT * FROM products WHERE name LIKE '% + name + %'");
//$articlesor->execute(array(
//'name' => $productname
//));
//while($articlecek=$articlesor->fetch(PDO::FETCH_ASSOC)) {
$servername = "localhost";
$username = "root";
$password = "PASSWORD";
$dbname = "fullcashback";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM products WHERE name LIKE '%$productname%'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
?>
<div class="col">
<div class="card shadow-sm">
<img style="max-height:300px;" src="<?php echo $row['imageurl'] ?>">
<div class="card-body">
<h3><?php echo $row['name'] ?></h3>
<p class="card-text"><?php echo $row['description'] ?></p>
<p style="color:green;">£<?php echo $row['discountedprice'] ?></p>
<strike style="color:red;">£<?php echo $row['price'] ?></strike>
<div class="d-flex justify-content-between align-items-center">
<div class="btn-group">
<a href="product.php?id=<?php echo $row['id'] ?>"><button type="button" class="btn btn-primary">Buy Now</button></a>
</div>
</div>
</div>
</div>
</div>
<?php //}
}
} else {
echo "No results";
}
$conn->close();
?>
</div>
</div>
</div>
</main>
<script>
function deleteCookie() {
document.cookie = "email=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
document.cookie = "password=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
location.reload();
}
var modal = document.getElementById("myModal");
// Get the button that opens the modal
var btn = document.getElementById("showModal");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
</body>
</html>