-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_profile_update.php
139 lines (104 loc) · 5.83 KB
/
user_profile_update.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
<?php
@include 'config.php';
session_start();
$user_id = $_SESSION['user_id'];
if(!isset($user_id)){
header('location:login.php');
};
if(isset($_POST['update_profile'])){
$name = $_POST['name'];
$name = filter_var($name);
$email = $_POST['email'];
$email = filter_var($email);
$update_profile = $conn->prepare("UPDATE `users` SET name = ?, email = ? WHERE id = ?");
$update_profile->execute([$name, $email, $user_id]);
$image = $_FILES['image']['name'];
$image = filter_var($image);
$image_size = $_FILES['image']['size'];
$image_tmp_name = $_FILES['image']['tmp_name'];
$image_folder = 'uploaded_img/'.$image;
$old_image = $_POST['old_image'];
if(!empty($image)){
if($image_size > 2000000){
$message[] = 'image size is too large!';
}else{
$update_image = $conn->prepare("UPDATE `users` SET image = ? WHERE id = ?");
$update_image->execute([$image, $user_id]);
if($update_image){
move_uploaded_file($image_tmp_name, $image_folder);
if(!empty($$old_image))
unlink('uploaded_img/'.$old_image);
$message[] = 'image updated successfully!';
};
};
};
$old_pass = $_POST['old_pass'];
$update_pass = md5($_POST['update_pass']);
$update_pass = filter_var($update_pass);
$new_pass = md5($_POST['new_pass']);
$new_pass = filter_var($new_pass);
$confirm_pass = md5($_POST['confirm_pass']);
$confirm_pass = filter_var($confirm_pass);
if(!empty($update_pass) AND !empty($new_pass) AND !empty($confirm_pass)){
if($update_pass != $old_pass){
$message[] = 'old password not matched!';
}elseif($new_pass != $confirm_pass){
$message[] = 'confirm password not matched!';
}else{
$update_pass_query = $conn->prepare("UPDATE `users` SET password = ? WHERE id = ?");
$update_pass_query->execute([$confirm_pass, $user_id]);
$message[] = 'password updated successfully!';
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>update user profile</title>
<!-- font awesome cdn link -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css">
<link href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABWoAAAVp8APVWfAKRVngDgVZ4A+FWeAPJWnwDMVqAAcVehAAZXogBnWKQAq1mmAJkAAAAAAAAAAAAAAABXoQAEVqAAllafAP5VnwD/VZ4A/1WeAP9VngD/Vp8A/1agAP9XoQCbV6IAq1ikAP9ZpgDkAAAAAAAAAAAAAAAAV6EAkFagAP9WnwD/VZ4A/1WeALpVngBiVZ4AUlafAIFWoADrV6EA+VeiANhYpAD/WaYA5AAAAAAAAAAAV6IAM1ehAP1WoAD/Vp8A/1WeAIJVngABAAAAAAAAAAAAAAAAVqAAIFehAOZYowD/WKQA/1mmAOQAAAAAAAAAAFeiAJ9WoQD/VqAA/1afAM1VngACAAAAAAAAAAAAAAAAAAAAAAAAAABXoQBmWKMA/1mkAP9apgDkAAAAAFijAAFXogDlVqEA/1agAP9WnwBrAAAAAAAAAAAAAAAAVZ8AE1afAD9WoAA/V6EAVlijAP9ZpQD/WqYA5AAAAABYowAUV6IA/lehAP9WoAD/Vp8AMgAAAAAAAAAAAAAAAFafAExWoAD/VqAA/1eiAP9YowD/WaUA/1qnAOQAAAAAWKMAJVeiAP9XoQD/VqAA/1afABgAAAAAAAAAAAAAAABWnwBMVqAA/1ehAP9XogD/WKMA/1mlAP9apwDkAAAAAFijACNXogD/V6EA/1agAP9WoAAXAAAAAAAAAAAAAAAAVp8AC1agACdXoQAnV6IAJ1ikACdZpQAnWqcAIgAAAABYpAANWKIA+1ehAP9XoQD/VqAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVqQAAFijANNXogD/V6EA/1agAGsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABYowALWaQAh1mmAIdaqACFW6oABQAAAABYpAB+WKMA/1eiAP9XoQDRVqEABAAAAAAAAAAAAAAAAAAAAAAAAAAAWKMAUFmlAP9apgD/W6gA4lyqAAEAAAAAWKQAElijAOtXogD/V6IA/1ehAI5XoQACAAAAAAAAAAAAAAAAWKMAD1ikANNZpQD/WqcA/1upAJEAAAAAAAAAAAAAAABYpABMWKMA+1eiAP9XogD/V6IAw1eiAGdXogBQWKIAdFijANxZpAD/WaYA/1qnAOtbqQAZAAAAAAAAAAAAAAAAAAAAAFikAEtYowDqWKMA/1eiAP9XogD/WKMA/1ijAP9YpAD/WaUA/1qmAONaqAA1AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWKQAEVijAHZYowDFWKMA71ijAPtYpADtWaQAwlmlAHRapwAOAAAAAAAAAAAAAAAA4AEAAMABAADAAQAAgcEAAIPhAAAHAQAABwEAAAcBAAAHAQAAB/8AAAfgAACD4AAAgcEAAMABAADgAwAA8AcAAA==" rel="icon" type="image/x-icon">
<!-- custom css file link -->
<link rel="stylesheet" href="css/components.css">
</head>
<body>
<?php include 'header.php'; ?>
<section class="update-profile">
<h1 class="title">update profile</h1>
<form action="" method="POST" enctype="multipart/form-data">
<img src="uploaded_img/<?= $fetch_profile['image']; ?>" alt="">
<div class="flex">
<div class="inputBox">
<span>username* :</span>
<input type="text" name="name" value="<?= $fetch_profile['name']; ?>" placeholder="update username" required class="box">
<span>email* :</span>
<input type="email" name="email" value="<?= $fetch_profile['email']; ?>" placeholder="update email" required class="box">
<span>update pic :</span>
<input type="file" name="image" accept="image/jpg, image/jpeg, image/png" class="box">
<input type="hidden" name="old_image" value="<?= $fetch_profile['image']; ?>">
<span>Fields marked with * are compulsory</span>
</div>
<div class="inputBox">
<input type="hidden" name="old_pass" value="<?= $fetch_profile['password']; ?>">
<span>Current password* :</span>
<input type="password" name="update_pass" placeholder="enter current password" class="box">
<span>new password :</span>
<input type="password" name="new_pass" placeholder="enter new password" class="box">
<span>confirm password :</span>
<input type="password" name="confirm_pass" placeholder="confirm new password" class="box">
</div>
</div>
<div class="flex-btn">
<input type="submit" class="btn" value="update profile" name="update_profile">
<a href="home.php" class="option-btn">go back</a>
</div>
</form>
</section>
<?php include 'footer.php'; ?>
<script src="js/script.js"></script>
</body>
</html>