/
Update_ProfilePage.php
373 lines (302 loc) · 17 KB
/
Update_ProfilePage.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Profile Update</title>
<link rel="stylesheet" href="stylesheets/styles.css" type="text/css" />
<link rel="stylesheet" href="fonts/style.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
</head>
<body class="main-wrapper">
<div id="wrapper">
<!-- Sidebar -->
<div id="sidebar-wrapper">
<ul class="sidebar-nav">
<li>
<img src="photofile/logo.png" class="img-logo-profile">
</li>
<li>
<h4 class="sub-txt-p" style="margin-left:-20px;">Pair It</h4>
</li>
<li>
<div class="verticalLine"></div>
</li>
<li>
<h4 class="sub-txt-p" style="margin-left:-20px;">Log Out</h4>
</li>
</ul>
</div>
<!-- /#sidebar-wrapper -->
<!-- Sidebar 2-->
<div id="sidebar-wrapper-two">
<br><br><br><br><br>
<a href="profile.php"><i class="profile-06 icons-active" style="margin-left:120px; color:#fff; font-size:90px;"></i></a>
<br><br><br><br>
<a href="index.php"><i class="blog icons" style="margin-left:120px; font-size:90px;"></i></a>
<br><br><br><br>
<a href="notifications.php"><i class="notifications icons" style="margin-left:120px; font-size:90px;"></i></a>
</div>
<!-- /#sidebar-wrapper -->
<!-- Page Content -->
<div id="page-content-wrapper">
<div class="container-fluid">
<div class="row" style="margin-top:-120px;">
<div class="col-lg-12">
<!--
<a href="">
<div class="circle">
<i class="fa fa-pencil edit-btn"></i>
</div>
</a>
-->
<!--start of php for image upload-->
<?php
session_start();
include 'connect.php';
/*if (isset($_SESSION['user_name'])) {
$username = $_SESSION['user_name'];
}
else {
echo "You have not signed in";
}*/
if($_SERVER['REQUEST_METHOD'] != 'POST')
{
echo '
<form action="Update_ProfilePage.php" method="post" enctype="multipart/form-data">
<img src="photofile/profile.png" class="img-logo-profile-pic">
<br><br>
<h4 class="sub-txt-style2">'.$_SESSION['user_name'].'</h4>
<div class="row">
<div class="col-sm-1"></div>
<div class="col-sm-5">
<input type="file" name="file_img" class="btn btn-default profile-btn"/>
</div>
<div class="col-sm-5">
<button type="submit" name="Update_photo" value="Upload photo" class="btn btn-default profile-btn">Save Upload Photo</button>
</div>
<div class="col-sm-1"></div>
</div>
</form>';
}
else
{
if(isset($_POST['Update_photo']))
{
$check = getimagesize($_FILES['file_img']['tmp_name']);
if($check !== false)
{
$filetmp = $_FILES['file_img']['tmp_name'];//file control name
$filename = $_FILES['file_img']['name'];
$filetype = $_FILES['file_img']['type'];
$filepath = "photofile/".$filename; //photofile = name of folder
move_uploaded_file($filetmp,$filepath);
$_SESSION['file_img'] = $filepath;
} else
{
echo "File is not an image";
}
}
$errors = array();
if(isset($_POST['first_name']))
{
if(!preg_match('/^[a-z0-9 .\-]+$/i', $_POST['first_name'])){
$errors[] = 'The first name can only contain letters and digits.';
}
if(strlen($_POST['first_name']) > 30){
$errors[] = 'The first name cannot be longer than 30 characters.';
}
if(strlen($_POST['first_name']) < 5){
$errors[] = 'The first name cannot be shorter than 5 characters.';
}
}else
{
$errors[] = 'The first field name must not be empty.';
}
if(isset($_POST['last_name']))
{
if(!preg_match('/^[a-z0-9 .\-]+$/i', $_POST['last_name'])){
$errors[] = 'The last name can only contain letters and digits.';
}
if(strlen($_POST['last_name']) > 30){
$errors[] = 'The last name cannot be longer than 30 characters.';
}
if(strlen($_POST['last_name']) < 5){
$errors[] = 'The last name cannot be shorter than 5 characters.';
}
}else
{
$errors[] = 'The last name field must not be empty.';
}
if(isset($_POST['location']))
{
if(!preg_match('/^[a-z0-9 .\-]+$/i', $_POST['location'])){
$errors[] = 'The location can only contain letters and digits.';
}
if(strlen($_POST['location']) > 30){
$errors[] = 'The location cannot be longer than 30 characters.';
}
if(strlen($_POST['location']) < 5){
$errors[] = 'The location cannot be shorter than 5 characters.';
}
}else
{
$errors[] = 'The location field must not be empty.';
}
if(isset($_POST['user_email']))
{
if(!filter_var($_POST['user_email'], FILTER_VALIDATE_EMAIL)){
$errors[] = 'Invalid email format';
}
if(strlen($_POST['user_email']) > 30){
$errors[] = 'The email cannot be longer than 30 characters.';
}
if(strlen($_POST['user_email']) < 5){
$errors[] = 'The email cannot be shorter than 5 characters.';
}
}else
{
$errors[] = 'The email field must not be empty.';
}
if(!empty($errors))
{
echo 'Some of the fields are filled in incorrectly';
echo '<ul>';
foreach($errors as $key => $value)
{
echo '<li>' . $value . '</li>';
}
echo '</ul>';
}
else
{
class User
{
public $user_name;
public $first_name;
public $last_name;
public $location;
public $user_email;
}
function sanitise($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$first_name= sanitise($_POST['first_name']);
$last_name= sanitise($_POST['last_name']);
$location= sanitise($_POST['location']);
$user_email= sanitise($_POST['user_email']);
$user_name = $_SESSION['user_name'];
echo 'Profile of ' . $_SESSION['user_name'].'.<br/>';
$update ="UPDATE users SET first_name='$first_name' WHERE user_name= '$user_name'";
$inserted=mysql_query($update);
$update="UPDATE users SET last_name='$last_name' WHERE user_name= '$user_name' ";
$inserted=mysql_query($update);
$update="UPDATE users SET location='$location' WHERE user_name='$user_name'";
$inserted=mysql_query($update);
$update="UPDATE users SET user_email='$user_email' WHERE user_name= '$user_name'";
$inserted=mysql_query($update);
//session must change
if(!$inserted)
{
echo 'Something went wrong. Please try again
later.';
}
else
{
echo 'Successfully updated.';
echo '<a href="profilePage.php">Profile Page</a> and <br/>
';
}
}
}
?>
<!--end of php for image upload-->
<hr class="hr-white">
<div class="row">
<div class="col-sm-1"></div>
<div class="col-sm-10">
<?php
//echo "The name is ".$_SESSION['user_name']."";
$user_name = $_SESSION['user_name'];
$sql = mysql_query("SELECT user_rep FROM users WHERE user_name='$user_name'");
$rep = mysql_result($sql,0,'users.user_rep');
//echo "POINTS = $rep";
if ($rep >= 0 && $rep <=5)
{
echo "<h2 type='text' class='btn btn-default profile-btn'>Wine Rookie.
Points = $rep</h2>";
} else if ($rep >= 6 && $rep <=20)
{
echo "<h2 type='text' class='btn btn-default profile-btn'>Wine Enthusiast.
Points = $rep</h2>";
} else if ($rep >= 21)
{
echo "<h2 type='text' class='btn btn-default profile-btn'>Wine Sommaelier.
Points = $rep</h2>";
} else
{
echo "<h2 type='text' class='btn btn-default profile-btn'>No Reputation</h2>";
}
?>
</div>
<div class="col-sm-1"></div>
</div>
<!--start of form-->
<form action="Update_ProfilePage.php" method="POST">
<div class="row">
<div class="col-sm-1"></div>
<div class="col-sm-10">
<h4 class="sub-txt" style="text-align:left; margin-top:60px; font-weight:200;">About Me</h4>
<input type="text" class="form-control" name="about_me">
</div>
<div class="col-sm-1"></div>
</div>
<div class="row">
<div class="col-sm-1"></div>
<div class="col-sm-5">
<h4 class="sub-txt" style="text-align:left; margin-top:60px; font-weight:200;">Name</h4>
<input type="text" class="form-control" name="first_name">
</div>
<div class="col-sm-5">
<h4 class="sub-txt" style="text-align:left; margin-top:60px; font-weight:200;">Surname</h4>
<input type="text" class="form-control" name="last_name">
</div>
<div class="col-sm-1"></div>
</div>
<div class="row">
<div class="col-sm-1"></div>
<div class="col-sm-5">
<h4 class="sub-txt" style="text-align:left; margin-top:60px; font-weight:200;">Location</h4>
<input type="text" class="form-control" name="location">
</div>
<div class="col-sm-5">
<h4 class="sub-txt" style="text-align:left; margin-top:60px; font-weight:200;">Email</h4>
<input type="text" class="form-control" name="user_email">
</div>
<div class="col-sm-1"></div>
</div>
<br><br><br>
<div class="row" style="margin-bottom:100px;">
<div class="col-sm-1"></div>
<div class="col-sm-10">
<button type="submit" value="Update" name="Update_info" class="btn btn-default" style="width:100%">Update</button>
</div>
<div class="col-sm-1"></div>
</div>
</form> <!-- /#end of form -->
</div>
</div>
</div>
</div>
<!-- /#page-content-wrapper -->
</div>
<!-- /#wrapper -->
</body>
<script src="javascripts/bootstrap.min.js"></script>
<?php
mysql_close();
?>
</html>