-
Notifications
You must be signed in to change notification settings - Fork 1
/
EditProfile.php
executable file
·164 lines (148 loc) · 4.03 KB
/
EditProfile.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
<?php
session_start();
include_once 'DBconnect.php';
include "NavigationBar.php";
if(!isset($_SESSION['user']))
{
header("Location: Login.php");
}
$res=mysqli_query($connection,"SELECT * FROM users WHERE user_id=".$_SESSION['user']);
$row=mysqli_fetch_array($res);
if(isset($_POST['btn-login']))
{
$username = mysqli_real_escape_string($connection,$_POST['username']);
$userlname = mysqli_real_escape_string($connection,$_POST['userlname']);
$email = mysqli_real_escape_string($connection,$_POST['email']);
$upass = mysqli_real_escape_string($connection,$_POST['pass']);
$unewpass = md5(mysqli_real_escape_string($connection,$_POST['newpass']));
$uconfnewpass = md5(mysqli_real_escape_string($connection,$_POST['confnewpass']));
if($row['password']==md5($upass))
{
if($unewpass==$uconfnewpass){
if(mysqli_query($connection,"UPDATE users SET username='$username', email='$email', userlastname='$userlname',password='$unewpass' WHERE user_id=".$_SESSION['user']))
{
?>
<script>alert('successfully updated ');</script>
<?php
header("Location: Homepage.php");
}
else
{
?>
<script>alert('error while updating your profile...');</script>
<?php
}
}
else
{
?>
<script>alert('New and Confirm passwords do not match');</script>
<?php
}
}
else
{
?>
<script>alert('wrong password');</script>
<?php
}
}
include( 'ImageFunction.php');
// settings
$max_file_size = 1024*200; // 200kb
$valid_exts = array('jpeg', 'jpg', 'png', 'gif');
// thumbnail sizes
$sizes = array(50 => 50, 250 => 250);
if ($_SERVER['REQUEST_METHOD'] == 'POST' AND isset($_FILES['image'])) {
if( $_FILES['image']['size'] < $max_file_size ){
// get file extension
$ext = strtolower(pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION));
if (in_array($ext, $valid_exts)) {
/* resize image */
foreach ($sizes as $w => $h) {
$files[] = resize($w, $h);
}
} else {
$msg = 'Unsupported file';
}
} else{
$msg = 'Please upload image smaller than 200KB';
}
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Profile Edit</title>
<link rel="stylesheet" href="stylecss.css" type="text/css" />
<meta charset="utf-8">
</head>
<body>
<center>
<table align="center" width="80%" border="0">
<td width="20%">
<?php
// show image thumbnails
if(isset($files)){
foreach ($files as $image) {
if(stripos($image, "250") !== false){
echo "<img class='img' src='{$image}' /><br /><br />";
}
else {
mysqli_query($connection,"UPDATE users SET imgage='$image' WHERE user_id=".$_SESSION['user']);
}
}
}
?>
<div >
<!-- file uploading form -->
<form action="" method="post" enctype="multipart/form-data">
<label>
<span>Choose image</span><br><br>
<input type="file" name="image" accept="image/*" /></input><br>
</label>
<br>
<input type="submit" value="Upload" /></input>
</form>
</div>
<?php if(isset($msg)): ?>
<p class='alert'><?php echo $msg ?></p>
<?php endif ?>
</td>
<td>
<div id="login-form">
<form method="post"><table align="center" width="50%" border="0">
<table align="center" width="80%" border="0">
<tr>
<td><input type="text" name="username" placeholder="Your New Name" required /></td>
</tr>
<tr>
<td><input type="text" name="userlname" placeholder="Your New Last Name" required /></td>
</tr>
<tr>
<td><input type="text" name="email" placeholder="Your New Email" required /></td>
</tr>
<tr>
<td><input type="password" name="pass" placeholder="Your Password" required /></td>
</tr>
<tr>
<td><input type="password" name="newpass" placeholder="Your New Password" required /></td>
</tr>
<tr>
<td><input type="password" name="confnewpass" placeholder="Confirm New Password" required /></td>
</tr>
<tr>
<td><button type="submit" name="btn-login">Edit</button></td>
</tr>
<tr>
<td><a href="Homepage.php">Back</a></td>
</tr>
</table>
</form>
</div>
</td>
</table>
</center>
</body>
</html>