-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.php
118 lines (109 loc) · 5.1 KB
/
profile.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
<?php require_once __DIR__ . "/include/layout-start.php"; ?>
<?php
if(!$helper->isUserLogin()){
$helper->Redirect(BASE_URL . 'login.php');
}
$user_id = $_SESSION['uid'];
$sql = "SELECT * FROM tbl_users WHERE id = $user_id";
$result = $conn -> query($sql);
$user_row = $result -> fetch_assoc();
if(isset($_POST['profileUpdate'])){
$name = $conn->real_escape_string($_POST['name']);
$phone = $conn->real_escape_string($_POST['phone']);
$aboutme = $conn->real_escape_string($_POST['aboutme']);
$role = ROLE::USER;
$sql = "UPDATE tbl_users SET name='$name', phone='$phone', aboutme='$aboutme' WHERE id = $user_id";
$result = $conn -> query($sql);
if($result){
$helper->SendSuccessToast("Profile Updated Sucessfully");
$helper->Redirect(BASE_URL . 'profile.php');
} else {
$helper->SendSuccessToast("Update Profile Failed!!");
$helper->Redirect(BASE_URL . 'profile.php');
}
}
if(isset($_POST['passwordUpdate'])){
$old_password = $conn->real_escape_string($_POST['oldPassword']);
$password = $conn->real_escape_string($_POST['newPassword']);
$sql = "SELECT * FROM `tbl_users` WHERE id = $user_id AND password = '$old_password'";
$result = $conn -> query($sql);
$row = $result -> fetch_assoc();
if($row !== false && !empty($row)){
$sql = "UPDATE tbl_users SET password='$password' WHERE id = $user_id";
$resultUpdate = $conn -> query($sql);
if($resultUpdate){
$helper->SendSuccessToast("Password Changed Sucessfully");
$helper->Redirect(BASE_URL . 'profile.php');
} else {
$helper->SendErrorToast("Password Update Failed!!");
$helper->Redirect(BASE_URL . 'profile.php');
}
} else {
$helper->SendErrorToast("Old Password Incorrect!!");
$helper->Redirect(BASE_URL . 'profile.php');
}
}
?>
<section class="jumbotron text-center">
<div class="container">
<h1 class="jumbotron-heading">My Profile</h1>
<p class="lead text-muted mx-5 px-5">You Update Your Details or Change Password.</p>
</div>
</section>
<div class="container">
<div class="row">
<div class="col-6">
<div class="card">
<div class="card-header">
<h4 class="card-title m-0">Profile</h4>
</div>
<div class="card-body">
<form method="post">
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" name="name" value="<?=$user_row['name']?>" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" name="email" value="<?=$user_row['email']?>" required disabled>
</div>
<div class="mb-3">
<label for="phone" class="form-label">Phone</label>
<input type="tel" class="form-control" id="phone" name="phone" value="<?=$user_row['phone']?>" required>
</div>
<div class="mb-3">
<label for="aboutme" class="form-label">Amout Me</label>
<textarea class="form-control" id="aboutme" name="aboutme" required><?=$user_row['aboutme']?></textarea>
</div>
<div class="mb-3">
<label for="reg" class="form-label">Registration Date</label>
<input type="text" class="form-control" id="reg" name="reg" value="<?=$user_row['created_at']?>" disabled>
</div>
<button type="submit" name="profileUpdate" class="btn btn-primary">Update</button>
</form>
</div>
</div>
</div>
<div class="col-6">
<div class="card">
<div class="card-header">
<h4 class="card-title m-0">Change Password</h4>
</div>
<div class="card-body">
<form method="post">
<div class="mb-3">
<label for="oldPassword" class="form-label">Old Password</label>
<input type="password" class="form-control" id="oldPassword" name="oldPassword" required>
</div>
<div class="mb-3">
<label for="newPassword" class="form-label">New Password</label>
<input type="password" class="form-control" id="newPassword" name="newPassword" required>
</div>
<button type="submit" name="passwordUpdate" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</div>
</div>
</div>
<?php require_once __DIR__ . "/include/layout-end.php"; ?>