-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.php
More file actions
168 lines (110 loc) · 4.62 KB
/
Copy pathupdate.php
File metadata and controls
168 lines (110 loc) · 4.62 KB
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
<!-- Source code for handling registration and login -->
<?php include('checkregister.php'); ?>
<head>
<title>update | Afya bood donation system</title>
<link rel="stylesheet" type="text/css" href="../styles.css">
</head>
<body>
<?php include('includes/navbarin.php')?>
<?php include('includes/mininav.php') ?>
<?php
include ('../includes/conn.php');
session_start();
$id=$_SESSION['username'];
$query=mysqli_query($db,"SELECT * FROM users where username='$id'");
$row=mysqli_fetch_array($query);
?>
<div class="content" style="float:left; margin-left:10% ">
<h2> Update your profile</h2>
<?php include('includes/errors.php') ?>
<div class="profile-input-field">
<form method="post" action="#" >
<div class="input-group">
<label>Full name</label> (real name)
<input type="text" name="fullname" value="<?php echo $row['fullname']; ?>" required />
</div>
<div class="input-group">
<label>Email</label>
<input type="email" name="email" required value="<?php echo $row['email']; ?>" />
<label>county</label>
<select name="county" class="county">
<option value="<?php echo $row['county']; ?>"><?php echo $row['county']; ?></option>
<option value="Nyeri"> Nyeri</option>
<option value="Kiambu ">Kiambu</option>
<option value="Kirinyaga">Kirinyaga</option>
<option value="Muranga">Muranga</option>
<option value="Nyandarua"> Nyandarua</option>
</select>
</div>
<div class="input-group">
<button type="submit" class="btn" name="update">Update profile</button>
</div>
</div>
</div>
</form>
</div>
<!-- pass -->
<div class="content" style="float:right; margin-right:10%" >
<form method="post" action="update.php">
<?php include('../includes/errors.php') ?>
<h2>Change password
</h2>
<div class="input-group">
Please input your old password<br><hr>
<label>Old password <star style="color:red" > * </star></label>
<input type="password" required name="password" placeholder="Old Password">
<label>New password <star style="color:red" > * </star></label>
<input type="password" required name="password_1" placeholder="New Password.">
<label>confirm new password <star style="color:red" > * </star></label>
<input type="password" required name="password_2" placeholder="Re-Type New Password">
<div class="input-group">
<button type="submit" class="btn" name="re_password">Change password</button>
</div></div>
</form>
</html>
<?php
if(isset($_POST['update'])){
$fullname = mysqli_real_escape_string($db, $_POST['fullname']);
$username = mysqli_real_escape_string($db, $_POST['username']);
$email = mysqli_real_escape_string($db, $_POST['email']);
$county = mysqli_real_escape_string($db,$_POST['county']);
$query = "UPDATE users SET fullname = '$fullname', email = '$email', county= '$county'
WHERE username = '$id'";
$result = mysqli_query($db, $query) or die(mysqli_error($db));
?>
<script type="text/javascript">
alert(" Profile Update Successfull.");
window.location = "account.php";
</script>
<?php
}
?>
<!-- re pass -->
<?php
if(isset($_POST['re_password'])){
$password = mysqli_real_escape_string($db, $_POST['password']);
$password_1 = mysqli_real_escape_string($db, $_POST['password_1']);
$password_2 = mysqli_real_escape_string($db, $_POST['password_2']);
if ($password_1 != $password_2) { ?> <star style="color:red" >The confirm password does not match with your new password <br> </star> <?php ; }
$password = md5($password);
$query = "SELECT * FROM users WHERE username='$id' AND password='$password'";
$result=mysqli_query($db,$query);
$row=mysqli_fetch_array($result);
$active=$row['active'];
$count=mysqli_num_rows($result);
if($count==1 ) {
$password_1 = md5($password_1);
$query = "UPDATE users SET password = '$password_1' WHERE username = '$id'";
$result = mysqli_query($db, $query) or die(mysqli_error($db));
?>
<script type="text/javascript">
alert(" Profile Update Successfull.");
window.location = "account.php";
</script>
<?php
}
else if ($count!=1) {
?> <star style="color:red" >make sure you have entered your correct old password <br> </star> <?php ;
}
}
?>