-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodify_php.php
More file actions
67 lines (55 loc) · 1.75 KB
/
Copy pathmodify_php.php
File metadata and controls
67 lines (55 loc) · 1.75 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
<?php
require_once 'db.php';
if ( $_SESSION['logged_in'] != 1 ) {
$_SESSION['message'] = "You must log in";
header("location: error.php");
exit(0);
}
$old_id = $_SESSION["old_id"];
$old_email = $_SESSION["old_email"];
$id = $_POST["id"];
$first_name = $_POST["first_name"];
$last_name = $_POST["last_name"];
$email = $_POST["email"];
$admin = $_POST['admin'];
$result = $mysqli->query('SELECT * FROM '. DB .".users WHERE id= '$id'");
if ($result->num_rows!=0 && $id!=$old_id){
$_SESSION['message'] = 'User with this id already exists!';
header("location: error.php");
exit(0);
}
$result = $mysqli->query('SELECT * FROM '. DB .".users WHERE email= '$email'");
if ($result->num_rows!=0 && $email!=$old_email){
$_SESSION['message'] = 'User with this email already exists!';
header("location: error.php");
exit(0);
}
$pass = NULL;
if ($admin)
{
//Hash the password for storing in the database
$pass = password_hash($_POST['password'], PASSWORD_BCRYPT);
}
//Update the user information and alter the login table
$update = 'UPDATE '. DB .".users SET
id = '$id',
first_name = '$first_name',
last_name = '$last_name',
email = '$email',
password = '$pass',
admin = $admin
WHERE email = '$old_email'; " .
'ALTER TABLE ' . DB . ".`$old_id` RENAME TO " . DB . ".`$id`";
if ($mysqli->multi_query($update))
{
$_SESSION['message'] = 'User modified!';
header("location: success.php");
exit(0);
}
else
{
$_SESSION['message'] = 'Update failed!';
header("location: error.php");
exit(0);
}
?>