-
Notifications
You must be signed in to change notification settings - Fork 3
/
edit_profile.php
238 lines (216 loc) · 9.08 KB
/
edit_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
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
<?php
session_start();
if(!isset($_SESSION["user"]))
header("Location:index.php");
//connect to database
require_once('db_connect.php');
$flag = 0;
$isInput = 0;
//if edit profile is clicked
if(isset($_GET['uid'])){
$uid = $_GET['uid'];
$query = "SELECT * FROM users WHERE id='$uid'";
$result = mysqli_query($link,$query);
$row = mysqli_fetch_array($result);
}
//if update is clicked under edit profile
if (isset($_POST["update_profile"])) {
$uid = $_GET['uid'];
$query = "SELECT * FROM users WHERE id='$uid'";
$result = mysqli_query($link,$query);
$row = mysqli_fetch_array($result);
//if username is not NULL
if(trim($_POST["name"])!=NULL){
$name=$_POST["name"];
$query="UPDATE users SET name='$name' WHERE id='$uid'";
$result = mysqli_query($link,$query);
$_SESSION["name"] = $name;
$isInput++;
}
//if password is not NULL and check if its < 6 chars
if(trim($_POST["pass"])!=NULL && strlen($_POST["pass"])<6){
$flag=1;
$msg="Password should be of minimum 6 letters";
}
else if(trim($_POST["pass"])!=NULL && $flag==0){
$pass = md5($_POST["pass"]);
$query="UPDATE users SET password='$pass' WHERE id='$uid'";
$result = mysqli_query($link,$query);
$_SESSION["pass"] = $pass;
$isInput++;
}
//if mobile is not NULL and check if its 10 digit
if(trim($_POST["mobile"])!=NULL && !is_numeric($_POST["mobile"])){
$flag=1;
$msg="Invalid number.Enter digits.";
}
else if(trim($_POST["mobile"])!=NULL && strlen($_POST["mobile"])!=10){
$flag=1;
$msg="Invalid mobile number";
}
else if(trim($_POST["mobile"])!=NULL && $flag==0){
$mobile = $_POST["mobile"];
$query="UPDATE users SET mobile='$mobile' WHERE id='$uid'";
$result = mysqli_query($link,$query);
$_SESSION["mobile"] = $mobile;
$isInput++;
}
//if email is not NULL
if(trim($_POST["email"])!=NULL){
$email = $_POST["email"];
$query="UPDATE users SET email='$email' WHERE id='$uid'";
$result = mysqli_query($link,$query);
$_SESSION["email"] = $email;
$isInput++;
}
if($flag)
{
echo '<div class="alert alert-danger alert-dismissable fade in" style="position:absolute;margin-top:425px;margin-left:410px;width:350px;">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>' . $msg . '</div>';
}
else{
if($isInput){
$msg = "Details successfully updated !!";
echo '<div class="alert alert-success alert-dismissable fade in" style="position:absolute;margin-top:425px;margin-left:410px;width:350px;">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>' . $msg . '</div>';
}
else if(!$isInput){
$msg = "No input to update !!";
echo '<div class="alert alert-danger alert-dismissable fade in" style="position:absolute;margin-top:425px;margin-left:410px;width:350px;">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>' . $msg . '</div>';
}
}
unset($_POST);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="shortcut icon" type="image/png" href="Images/favicon.png">
<title>Profile</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="CSS/style.css">
<script type="text/javascript" src="JS/script.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row"><!--start of row-->
<div class="col-md-3">
<div class="row"><!--nested row starts-->
<div class="col-md-3" align="center" style="background-color:#1A1927;position:fixed"><!--libromate logo-->
<a href="dashboard.php"><img src="Images/logo.png" style="height:100px;"></a>
</div>
<div id="dashboard_left_col" style="padding-top:100px"><!--start of vertical navbar-->
<ul>
<br>
<p>MENU</p>
<li><a href="dashboard.php">
<span class="glyphicon glyphicon-home"></span> Dashboard</a>
</li>
<li><a href="profile.php">
<span class="glyphicon glyphicon-user"></span> Profile</a>
</li>
<br>
<p>BOOKS</p>
<li><a href="add.php">
<span class="glyphicon glyphicon-plus"></span> Add</a>
</li>
<li><a href="modify.php">
<span class="glyphicon glyphicon-edit"></span> Modify</a>
</li>
<li><a href="browse.php">
<span class="glyphicon glyphicon-eye-open"></span> Browse all</a>
</li>
<br>
<p>STATUS</p>
<li><a href="borrow.php">
<span class="glyphicon glyphicon-hourglass"></span> Borrowed
<?php
if($borrow!=0) {
echo "<span class='badge'>$borrow</span>";
}
?>
</a>
</li>
<li><a href="lent.php">
<span class="glyphicon glyphicon-book"></span> Lent
<?php
if($lent!=0) {
echo "<span class='badge'>$lent</span>";
}
?>
</a>
</li>
<br>
<p>SESSION</p>
<li><a href="logout.php">
<span class="glyphicon glyphicon-log-out"></span> Logout</a>
</li>
<li><a href="trash.php">
<span class="glyphicon glyphicon-trash"></span> Trash</a>
</li>
</ul>
</div><!--end of vertical navbar-->
</div><!--end of nested row-->
</div><!--end of col-md-3-->
<?php
include "topnav.php";
?>
<div class="container-fluid">
<br>
<div style="font-size:30px;padding-left: 70px">Enter Details</div>
<br>
<div class="container" style="padding-left: 70px">
<form action="edit_profile.php?uid=<?php echo $_SESSION["user_id"]; ?>" method="post">
<!--display username-->
<div class="input-group">
<span class="input-group-addon" style="width: 100px;">Username</span>
<input type="text" disabled="disabled" class="form-control" style="width:250px;" name="uname" placeholder="<?php echo $_SESSION["user"];?>">
</div>
<!--edit name-->
<div class="input-group">
<span class="input-group-addon" style="width: 100px;">Name</span>
<input type="text" class="form-control" style="width:250px;" name="name" placeholder="<?php echo $_SESSION["name"];?>">
</div>
<!--edit password-->
<div class="input-group">
<span class="input-group-addon" style="width: 100px;">Password
</span>
<span class="glyphicon glyphicon-alert" data-toggle="tooltip" title="Password should have minimum 6 characters" data-placement="bottom" style="color:#E74C3C;padding-top: 10px;padding-left: 5px"></span>
<input type="text" class="form-control" style="width:250px;" name="pass" placeholder="<?php echo $_SESSION["pass"];?>">
</div>
<!--edit mobile-->
<div class="input-group">
<span class="input-group-addon" style="width: 100px;">Mobile
</span>
<span class="glyphicon glyphicon-alert" data-toggle="tooltip" title="Enter a valid 10-digit mobile number" data-placement="bottom" style="color:#E74C3C;padding-top: 10px;padding-left: 5px">
</span>
<input type="text" class="form-control" style="width:250px;" name="mobile" placeholder="<?php echo $_SESSION["mobile"];?>">
</div>
<!--edit email-->
<div class="input-group">
<span class="input-group-addon" style="width: 100px;">E-Mail</span>
<input type="email" class="form-control" style="width:250px;" name="email" placeholder="<?php echo $_SESSION["email"];?>">
</div>
<br>
<div style="float: left; width: 170px">
<input class="btn btn-block btn-primary" type="submit" name="update_profile" value="Update">
</div>
<div style="float: right; width: 170px;margin-right:735px;">
<input class="btn btn-block btn-primary" type="button" name="cancel" value="Cancel" onclick="javascript:history.back();">
</div>
</form><!--end of form-->
</div><!--end of container-->
</div>
</div>
</div><!--end of col-md-9-->
</div><!--end of row-->
</div><!--end of container fluid-->
</body>
</html>