-
Notifications
You must be signed in to change notification settings - Fork 0
/
edituser.php
142 lines (109 loc) · 3.72 KB
/
edituser.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
<?php require_once("inc/connection.php") ?>
<?php session_start() ?>
<?php require_once("inc/nav.php") ?>
<?php
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
}
$email = "";
$firstname = "";
$lastname = "";
$password = "";
$user_id = "";
if(isset($_GET["userid"])){
$user_id = mysqli_real_escape_string($conn,$_GET['userid']);
$query = "SELECT * FROM user WHERE id='$user_id'";
$result = mysqli_query($conn,$query);
if($result){
if(mysqli_num_rows($result) == 1){
$record = mysqli_fetch_assoc($result);
$email = $record["email"];
$password = $record["password"];
$firstname = $record["first_name"];
$lastname= $record["last_name"];
}else{
header("Location: users.php?user=notfund");
}
}else{
die("Faild");
}
}else{
if(!isset($_POST['user_id'])){
header("Location:users.php?something=wrong");
}
}
$error = array();
if(isset($_POST['submit'])){
echo "<pre>";
echo print_r($_POST);
echo "</pre>";
$user_id = mysqli_real_escape_string($conn,$_POST['user_id']);
$firstname = mysqli_real_escape_string($conn,$_POST['firstname']);
$lastname = mysqli_real_escape_string($conn,$_POST['lastname']);
$email = mysqli_real_escape_string($conn,$_POST['email']);
$queryemailcheck = "SELECT * FROM user WHERE email='{$email}' AND id !={$user_id}";
$resultset1 = mysqli_query($conn, $queryemailcheck);
if($resultset1){
if(mysqli_num_rows($resultset1) == 1){
$error[] = "Email already exit";
}else{
$queryupdate = "UPDATE user SET first_name='{$firstname}' , last_name='{$lastname}' , email='{$email}' WHERE id='{$user_id}'";
$resultUpdate = mysqli_query($conn, $queryupdate);
if($resultUpdate){
header("Location: users.php?userupdate=done");
}else{
}
}
}
}
?>
<body>
<div class="container">
<div class="row">
<h2>Edit User<span><a href="users.php">+View user</a></span></h2>
</div>
<div class="row justify-content-center mt-5">
<div class="col-8">
<form action="edituser.php" method="post">
<div>
<?php
if(isset($error) && !empty($error)){
echo "<div class='emailAlert' id='email_alert'>";
foreach ($error as $er) {
echo $er;
}
echo "</div>";
}
?>
<input type="hidden" name="user_id" value="<?php echo $user_id ?>">
<label for="email" class="form-lable">Email</label>
<input <?php echo 'value="' . $email . '"' ?> type="text" id="email" name="email" class="form-control input-f ">
<div class="emailNewAlert" id="email_alert" role="alert">
</div>
</div>
<div class="mt-2">
<label for="firstname" class="form-lable">First Name</label>
<input <?php echo 'value="' . $firstname . '"' ?> type="text" id="firstname" name="firstname" class="form-control input-f" aria-describedby="firstnameHelpBlock">
<div id="firstnameHelpBlock" class=" firstnameHelpBlock form-text">
</div>
</div>
<div class="mt-2">
<label for="last_name" class="form-lable">Last Name</label>
<input <?php echo 'value="' . $lastname . '"' ?> type="text" id="last_name" name="lastname" class="form-control input-f"aria-describedby="lasnameHelpBlock">
<div id="lasnameHelpBlock" class="form-text">
</div>
</div>
<div class="mt-2">
<label for="password" class="form-lable col-12 col-md-2">Password</label>
<a href="changepassword.php?userid=<?php echo $user_id ?>">Change password</a>
</div>
<div class="mt-3">
<button class="btn bg-info" id="button" name="submit" type="submit">Submit</button>
</div>
</form>
</div>
</div>
</div>
<script src="js/edituser.js">
</script>
</body>