-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditform.php
425 lines (354 loc) · 19.9 KB
/
editform.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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
<?php
session_start();
global $user;
global $username;
$servername = "kinraidee-db.c1oo0oq4mfrf.ap-southeast-2.rds.amazonaws.com";
$dbusername = "narinphat";
$dbpassword = "abcd1234";
$dbname = "Kinraidee";
$username = $_SESSION['username'];
$row = "";
$conn = mysqli_connect($servername, $dbusername, $dbpassword, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
if ($username == NULL) {
header("Location: login.php");
}
$conn->set_charset("utf8");
$query = "
SELECT * FROM user
WHERE email = '$username'
";
$result = mysqli_query($conn, $query);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>KinRaiDee</title>
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<meta content="Free HTML Templates" name="keywords">
<meta content="Free HTML Templates" name="description">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/editform_css.css">
<link rel="stylesheet" href="css/navbar_css.css">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@200;300;400;600&display=swap" rel="stylesheet">
<link
href="https://fonts.googleapis.com/css?family=Material+Icons|Material+Icons+Outlined|Material+Icons+Two+Tone|Material+Icons+Round|Material+Icons+Sharp"
rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<!-- Boxicons CDN Link -->
<link href='https://unpkg.com/boxicons@2.0.7/css/boxicons.min.css' rel='stylesheet'>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Fontawesome CDN Link -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Google Web Fonts -->
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Thai:wght@300&display=swap" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
</head>
<body>
<!-- Topbar Start -->
<div class="container-fluid bg-primary py-3 d-none d-md-block">
<div class="container">
<div class="row">
<div class="col-md-6 text-center text-lg-right">
<div class="d-inline-flex align-items-center">
<a class="text-white px-3" href="">
<!-- <i class="fab fa-facebook-f"></i> -->
</a>
<a class="text-white px-3" href="">
<!-- <i class="fab fa-twitter"></i> -->
</a>
<a class="text-white px-3" href="">
<!-- <i class="fab fa-linkedin-in"></i> -->
</a>
<a class="text-white px-3" href="">
<!-- <i class="fab fa-instagram"></i> -->
</a>
<a class="text-white pl-3" href="">
<!-- <i class="fab fa-youtube"></i> -->
</a>
</div>
</div>
</div>
</div>
</div>
<!-- Topbar End -->
<!-- Navbar Start -->
<div class="container-fluid position-relative nav-bar p-0">
<div class="container-lg position-relative p-0 px-lg-3" style="z-index: 9;">
<nav class="navbar navbar-expand-lg bg-white navbar-light shadow p-lg-0">
<a href="index.html" class="navbar-brand d-block d-lg-none">
</a>
<button type="button" class="navbar-toggler" data-toggle="collapse" data-target="#navbarCollapse">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-between" id="navbarCollapse">
<div class="navbar-nav ml-auto py-0">
<a class="nav-item nav-link active" id="main" style="font-size: 120%;">หน้าหลัก</a>
<a class="nav-item nav-link" id="random" style="font-size: 120%;">สุ่ม!</a>
</div>
<a class="navbar-brand mx-5 d-none d-lg-block">
<div class="logo" style="margin-left: 10%;">
<img src="img/logo2.png" id="kinraidee" width="100" height="100">
</div>
</a>
<div class="navbar-nav mr-auto py-0">
<a id="shop" class="nav-item nav-link" style="font-size: 120%;">ร้านทั้งหมด</a>
<a id="review" class="nav-item nav-link" style="font-size: 120%;">รีวิวล่าสุด</a>
<div class="containery">
<input type="text" name="searchy" id="searchy" placeholder="ค้นหา..." class="input" />
<a href="#" class="btny" id="btny" style="left: 20%;">
<i class="fa-solid fa-magnifying-glass"></i>
</a>
</div>
</div>
<div class="action">
<div class="profile" onclick="menuToggle();">
<div class="logo" style="margin-left: 10%;">
<?php
if (!$row = mysqli_fetch_array($result)) {
$querytemp = "SELECT user_id from user
WHERE email = '$username'";
$resulttemp = mysqli_query($conn, $querytemp);
$rowtemp = mysqli_fetch_array($resulttemp);
$uid = $rowtemp["user_id"];
} else {
$uid = $row['user_id'];
}
$image_base64 = base64_encode($row["photo"]);
echo '<img src="data:image/jpeg;base64,' . $image_base64 . '" style="width="100" height="100"></img>';
?>
</div>
</div>
<div class="menu" id="menu">
<h3 class="heyeiei" style="text-align: center;">
<?php
echo $row['full_name'] . " " . $row['last_name'];
?>
<?php
echo $row['email'];
?>
<div class="badge">
<div class="badge-container" style="background-color: dodgerblue;">
<?php
if ($row['is_seller'] == 1) {
echo "<h5>Seller</h5>";
} else {
echo "<h5>Buyer</h5>";
}
?>
</div>
</div>
</d>
<ul style="margin-top: 5%;">
<li>
<span class="material-icons icons-size">mode</span>
<a href="editform.php">Edit Account</a>
</li>
<?php
$uid = $row['user_id'];
$isSeller = $row['is_seller'];
$query = "SELECT * FROM restaurant WHERE user_id = '$uid'";
$result = mysqli_query($conn, $query);
if ($rownav = mysqli_fetch_array($result)) {
if ($isSeller == 1) {
echo '<li><span class="material-icons icons-size">shop</span>';
echo '<a href="editshop.php?id=' . $rownav['restaurant_id'] . '">Edit Shop</a></li>';
}
}
?>
<li style="margin-bottom: -20%;">
<span class="material-icons icons-size">logout</span>
<a href="login.php">Log out</a>
</li>
</ul>
</div>
</div>
<script>
function menuToggle() {
const toggleMenu = document.querySelector('.menu');
toggleMenu.classList.toggle('active')
}
</script>
</div>
</nav>
</div>
</div>
<!-- Navbar End -->
<section>
<div class="container-edit">
<div class="title">แก้ไขข้อมูลส่วนตัว</div>
<form action="#" id="Editform" name="Editform" method="post" enctype="multipart/form-data">
<div class="user-details">
<div class="input-box">
<span class="details">Email</span>
<input type="text" required id="email" name="email" value="<?php echo $username?>">
<p class="textID" id="text"></p>
</div>
<div class="input-box">
<span class="details">Password</span>
<input type="text" required id="password" name="password" value="<?php echo $row['password']?>">
<p class="textID" id="text1"></p>
</div>
<div class="input-box">
<span class="details">First Name</span>
<input type="text" required id="fname" name="fname" value="<?php echo $row['full_name']?>">
<p class="textID" id="text2"></p>
</div>
<div class="input-box">
<span class="details">Last Name</span>
<input type="text" required id="lname" name="lname" value="<?php echo $row['last_name']?>">
<p class="textID" id="text3"></p>
</div>
<br>
<div class="input-box">
<span class="details">Home No.</span>
<input type="text" required id="hnum" name="hnum" value="<?php echo $row['no_home']?>">
<p class="textID" id="text4"></p>
</div>
<div class="input-box">
<span class="details">Subdistrict</span>
<input type="text" required id="subdistrict" name="subdistrict" value="<?php echo $row['subdistrict']?>">
<p class="textID" id="text5"></p>
</div>
<div class="input-box">
<span class="details">District</span>
<input type="text" required id="district" name="district" value="<?php echo $row['district']?>">
<p class="textID" id="text6"></p>
</div>
<div class="input-box">
<span class="details">Province</span>
<input type="text" required id="province" name="province" value="<?php echo $row['province']?>">
<p class="textID" id="text7"></p>
</div>
<div class="input-box">
<span class="details">Postal Code</span>
<input type="text" required id="posnum" name="posnum" value="<?php echo $row['postal_code']?>">
<p class="textID" id="text8"></p>
</div>
<div class="input-box">
<span class="details">Phone Number</span>
<input type="text" required id="phonenum" name="phonenum" value="<?php echo $row['phone']?>">
<p class="textID" id="text9"></p>
</div>
</div>
<div id="HERE" ></div>
<div>
<strong>Select Image:</strong>
<input type="file" id="uploadfile" name="uploadfile" accept="image/*">
</div>
<br><br>
<div>
<input type="submit" class="btn" value="ยืนยันการแก้ไข">
</div>
<?php
ob_start();
?>
<?php
if (isset($_FILES['uploadfile']['error'])) {
$uploadError = $_FILES['uploadfile']['error'];
if ($uploadError !== UPLOAD_ERR_OK) {
$email = $_POST['email'] ;
$password = $_POST['password'] ;
$full_name = $_POST['fname'] ;
$last_name = $_POST['lname'] ;
$no_home = $_POST['hnum'] ;
$subdistrict = $_POST['subdistrict'] ;
$district = $_POST['district'] ;
$province = $_POST['province'] ;
$postal_code = $_POST['posnum'] ;
$addPhone = $_POST['phonenum'] ;
// $addphoto = $row['photo'];
$stmt = mysqli_prepare($conn, "UPDATE user SET email=?, password=?, full_name=?, last_name=?, no_home=?, subdistrict=?, district=?, province=?, postal_code=?, phone=? WHERE email = '$username'");
// Bind the values to the prepared statement
mysqli_stmt_bind_param($stmt, "ssssssssis", $email, $password, $full_name, $last_name, $no_home, $subdistrict, $district, $province, $postal_code, $addPhone);
// mysqli_stmt_bind_param($stmt, ":photo", $addphoto);
// Execute the statement
mysqli_stmt_execute($stmt);
if(mysqli_stmt_errno($stmt)){
echo "Error inserting record: " . mysqli_stmt_error($stmt);
} else {
echo "<script>Swal.fire({
width: 550,
padding: '2em',
position: 'center',
icon: 'success',
title: 'Success',
text: 'Profile are save',
showConfirmButton: true,
confirmButtonText: 'Yes',
confirmButtonColor : '#AACB73',
showDenyButton: true,
denyButtonText: 'cancle',
}).then((result) => {
if (result.isConfirmed) {
Swal.fire('Saved!', '', 'success').then((result) => {
window.location = './mainbuyer.php'; });
} else if (result.isDenied) {
Swal.fire('Changes are not saved', '', 'info')
}
});
</script>";
}
} else {
$imgData = addslashes(file_get_contents($_FILES['uploadfile']['tmp_name']));
$email = $_POST['email'] ;
$password = $_POST['password'] ;
$full_name = $_POST['fname'] ;
$last_name = $_POST['lname'] ;
$no_home = $_POST['hnum'] ;
$subdistrict = $_POST['subdistrict'] ;
$district = $_POST['district'] ;
$province = $_POST['province'] ;
$postal_code = $_POST['posnum'] ;
$addPhone = $_POST['phonenum'] ;
$stmt = mysqli_prepare($conn, "UPDATE user SET email=?, password=?, full_name=?, last_name=?, no_home=?, subdistrict=?, district=?, province=?, postal_code=?, phone=? ,photo='$imgData' WHERE email = '$username'");
// Bind the values to the prepared statement
mysqli_stmt_bind_param($stmt, "ssssssssis", $email, $password, $full_name, $last_name, $no_home, $subdistrict, $district, $province, $postal_code, $addPhone);
// mysqli_stmt_bind_param($stmt, ":photo", $imgData);
// Execute the statement
mysqli_stmt_execute($stmt);
if(mysqli_stmt_errno($stmt)){
echo "Error to updated: " . mysqli_stmt_error($stmt);
} else {
echo "<script>Swal.fire({
width: 550,
padding: '2em',
position: 'center',
icon: 'success',
title: 'Success',
text: 'Profile are save',
showConfirmButton: true,
confirmButtonText: 'Yes',
confirmButtonColor : '#AACB73',
showDenyButton: true,
denyButtonText: 'cancle',
}).then((result) => {
if (result.isConfirmed) {
Swal.fire('Saved!', '', 'success').then((result) => {
window.location = './mainbuyer.php'; });
} else if (result.isDenied) {
Swal.fire('Changes are not saved', '', 'info')
}
});
</script>";
}
}
}
?>
</form>
</div>
</section>
<script src="src/navbar_js.js"></script>
<script src="src/validate_js.js"></script>
</body>
</html>