-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyaccount.php
More file actions
330 lines (303 loc) · 14.1 KB
/
myaccount.php
File metadata and controls
330 lines (303 loc) · 14.1 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
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
<?php
include("database.php");
session_start();
// Check if user is logged in
if (isset($_SESSION['user_id'])) {
$user_id = $_SESSION['user_id'];
// Use prepared statement to prevent SQL injection
$query = "SELECT Username, FirstName, LastName, Email, Phone, Birthdate, ProfileImageUrl FROM Customers WHERE CustomerID = ?";
$stmt = $connect->prepare($query);
$stmt->bind_param("i", $user_id); // Assuming CustomerID is an integer
$stmt->execute();
$result = $stmt->get_result();
// Fetch user data
if ($user_data = $result->fetch_assoc()) {
$username = $user_data['Username'];
$firstName = $user_data['FirstName'];
$lastName = $user_data['LastName'];
$email = $user_data['Email'];
$phone = $user_data['Phone'];
$birthdate = $user_data['Birthdate'];
$profileImage = $user_data['ProfileImageUrl'];
} else {
// Handle case where user data is not found
echo "User not found.";
exit();
}
} else {
// Redirect to login if user not logged in
header('Location: index.php');
exit();
}
$errorMessage = ''; // Initialize an error message variable
$errorFields = []; // Array to hold error messages for specific fields
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Retrieve user input
$newUsername = trim($_POST['username']);
$newFirstName = trim($_POST['firstname']);
$newLastName = trim($_POST['lastname']);
$newEmail = trim($_POST['email']);
$newPhone = trim($_POST['phone']);
$newBirthdate = trim($_POST['dob']);
// Ensure fields are not empty
if (empty($newUsername) || empty($newEmail) || empty($newPhone) || empty($newFirstName) || empty($newLastName)) {
$errorMessage = "Please fill in all fields.";
} else {
// Check if new username, email, or phone number already exists
$checkQuery = "SELECT Username, Email, Phone FROM Customers WHERE CustomerID != ?";
$checkStmt = $connect->prepare($checkQuery);
$checkStmt->bind_param("i", $user_id);
$checkStmt->execute();
$checkResult = $checkStmt->get_result();
// Loop through results to check for duplicates
// After checking for duplicates
while ($row = $checkResult->fetch_assoc()) {
if ($row['Username'] === $newUsername) {
$errorFields['username'] = "Username is already taken.";
$newUsername = ''; // Set the input box to empty
}
if ($row['Email'] === $newEmail) {
$errorFields['email'] = "Email is already taken.";
$newEmail = ''; // Set the input box to empty
}
if ($row['Phone'] === $newPhone) {
$errorFields['phone'] = "Phone number is already taken.";
$newPhone = ''; // Set the input box to empty
}
}
$checkStmt->close();
// If there are any error messages, set the main error message
if (!empty($errorFields)) {
$errorMessage = implode(' ', $errorFields);
} else {
// Update user details
$updateQuery = "UPDATE Customers SET Username = ?, FirstName = ?, LastName = ?, Email = ?, Phone = ?, Birthdate = ? WHERE CustomerID = ?";
$updateStmt = $connect->prepare($updateQuery);
$updateStmt->bind_param("ssssssi", $newUsername, $newFirstName, $newLastName, $newEmail, $newPhone, $newBirthdate, $user_id);
if ($updateStmt->execute()) {
$_SESSION['username'] = $newUsername;
echo '<div class="loading-screen">
<div class="log-in">Successfully Saved</div>
<div class="loading-image">
<img src="https://res.cloudinary.com/drkmgpcad/image/upload/v1726841328/rahjpg3k7mdtnow4ttux.png" alt="Loading Image">
</div>
</div>
<style>
.loading-screen {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: linear-gradient(#E7E7E7, #818181, #9A9B84);
background-size: cover;
background-position: center;
background-repeat: no-repeat;
color: black;
text-align: center;
font-size: 50px;
z-index: 1000;
}
.log-in {
border: black solid 1px;
border-radius: 25px;
padding: 10px;
background-color: #57573f;
margin-bottom: 0px;
}
.loading-image img {
width: 100px;
height: 100px;
animation: spinY 1s linear infinite;
margin: 20px auto;
margin-top: 100px;
z-index: 9999;
}
@keyframes spinY {
0% { transform: rotateY(0deg); }
100% { transform: rotateY(360deg); }
}
</style>
<script>
setTimeout(function() {
window.location.href = "myaccount.php";
}, 3000);
</script>';
} else {
echo '<div class="loading-screen">
<div class="log-in">Something went wrong <br> Saving Failed</div>
<div class="loading-image">
<img src="https://res.cloudinary.com/drkmgpcad/image/upload/v1726841328/rahjpg3k7mdtnow4ttux.png" alt="Loading Image">
</div>
</div>
<style>
.loading-screen {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: linear-gradient(#E7E7E7, #818181, #9A9B84);
background-size: cover;
background-position: center;
background-repeat: no-repeat;
color: black;
text-align: center;
font-size: 45px;
z-index: 1000;
}
.log-in {
border: black solid 1px;
border-radius: 25px;
padding: 10px;
background-color: #57573f;
margin-bottom: 0px;
}
.loading-image img {
width: 100px;
height: 100px;
animation: spinY 1s linear infinite;
margin: 20px auto;
margin-top: 100px;
z-index: 9999;
}
@keyframes spinY {
0% { transform: rotateY(0deg); }
100% { transform: rotateY(360deg); }
}
</style>
<script>
setTimeout(function() {
window.location.href = "myaccount.php";
}, 3000);
</script>'; // Show error
}
$updateStmt->close();
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Account</title>
<link rel="stylesheet" href="myaccount.css">
<link rel="shortcut icon" href="https://res.cloudinary.com/drkmgpcad/image/upload/v1726841328/rahjpg3k7mdtnow4ttux.png" type="image/x-icon">
<link href="https://fonts.googleapis.com/css2?family=Beau+Rivage&display=swap" rel="stylesheet">
</head>
<body>
<header>
<div>
<a class="logo-div" href="homepage.php" target="_self" onclick="showLoadingScreen('Loading...')">
<img src="https://res.cloudinary.com/drkmgpcad/image/upload/v1726841328/rahjpg3k7mdtnow4ttux.png" alt="Logo">
<h1>Happy Ending</h1>
</a>
</div>
<div id="search-container">
<input type="text" id="search-query" placeholder="Search..." oninput="searchProducts()">
<div id="search-results" class="search-results"></div>
</div>
<div class="navbar">
<div class="icons">
<span class="cart-icon"><a href=""><img src="Images/cart.png" alt="Cart" id="cartIcon"></a></span>
<div class="profile-dropdown">
<span class="profile-icon"><img src="Images/userIcon.png" alt="User Icon" id="userIcon"></span>
<span class="username"><a href="myaccount.php" id="usernameLink"><?php echo htmlspecialchars($username); ?></a></span>
<ul class="dropdown-menu" id="dropdownMenu">
<li><a href="myaccount.php">My Account</a></li>
<li class="divider"></li>
<li><a href="#">My Purchases</a></li>
<li class="divider"></li>
<li><a href="logout.php">Logout</a></li>
</ul>
</div>
</div>
</div>
</header>
<main>
<div class="profile-container">
<h2>My Profile</h2>
<p>Manage your Profile</p>
<hr>
<br>
<?php if ($errorMessage): ?>
<div class="error"><?php echo htmlspecialchars($errorMessage); ?></div>
<?php endif; ?>
<form action="myaccount.php" method="post" id="profileForm">
<div class="form-content">
<div class="left-section">
<div class="form-group">
<label for="username">Username</label>
<input type="text" id="username" name="username" value="<?php echo htmlspecialchars($username); ?>" >
</div>
<div class="form-group">
<label for="firstname">First Name</label>
<input type="text" id="firstname" name="firstname" value="<?php echo htmlspecialchars($firstName); ?>" >
</div>
<div class="form-group">
<label for="lastname">Last Name</label>
<input type="text" id="lastname" name="lastname" value="<?php echo htmlspecialchars($lastName); ?>" >
</div>
<div class="form-group">
<label for="dob">Date of Birth</label>
<input type="date" id="dob" name="dob" value="<?php echo htmlspecialchars($birthdate); ?>">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" id="email" name="email" value="<?php echo htmlspecialchars($email); ?>">
</div>
<div class="form-group">
<label for="phone">Phone Number</label>
<input type="text" id="phone" name="phone" value="<?php echo htmlspecialchars($phone); ?>">
</div>
</div>
<div class="right-section">
<div class="profile-image-wrapper">
<img src="<?php echo htmlspecialchars($profileImage ?: 'Images/userIcon.png'); ?>" alt="Profile Image" class="profile-image">
</div>
<div class="form-group image-selector">
<label for="file-input" class="btn-save select-image-button">Select Image</label>
<input type="file" name="profile_image" id="file-input" accept=".jpg, .jpeg, .png" style="display: none;">
<div class="file-info">
<p>File size: maximum 2MB<br>File extension: JPEG, PNG</p>
</div>
</div>
</div>
</div>
<button type="button" class="save-button" onclick="showConfirmationModal()">Save Changes</button>
</form>
<!-- Confirmation Modal -->
<div id="confirmationModal" class="modal">
<div class="modal-content">
<span class="close" onclick="closeModal()">×</span>
<p>Are you sure you want to save the changes?</p>
<button id="yesButton">Yes</button>
<button id="noButton">No</button>
</div>
</div>
</div>
</main>
<footer>
<p class="copyright">© 2024 Happy Ending. All rights reserved.</p>
<nav>
<ul>
<li class="about-us"><a href="" onclick="showLoadingScreen('Loading...')">ABOUT US</a></li>
<li><a href="https://www.facebook.com" target="_blank" onclick="showLoadingScreen('Loading...')"><img class="icons-picture" src="https://res.cloudinary.com/drkmgpcad/image/upload/v1724068194/angoienw2wu8c1aqdrge.png" alt="FB-logo"></a></li>
<li><a href="https://www.instagram.com" target="_blank" onclick="showLoadingScreen('Loading...')"><img class="icons-picture" src="https://res.cloudinary.com/drkmgpcad/image/upload/v1726891138/zzzgspgokfq1sbc9sjmu.webp" alt="IG-logo"></a></li>
<li><a href="https://www.x.com" target="_blank" onclick="showLoadingScreen('Loading...')"><img class="icons-picture" src="https://res.cloudinary.com/drkmgpcad/image/upload/v1726890890/edvvrnyg1wewlm1onmzs.png" alt="X-logo"></a></li>
</ul>
</nav>
</footer>
<script src="myaccount.js"></script>
</body>
</html>