-
Notifications
You must be signed in to change notification settings - Fork 0
/
ac_update.php
109 lines (105 loc) · 4.58 KB
/
ac_update.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
<?php
session_start();
require('connectDB.php');
if (isset($_POST['update'])) {
$useremail = $_SESSION['Admin-email'];
$up_name = $_POST['up_name'];
$up_email = $_POST['up_email'];
$up_password =$_POST['up_pwd'];
if (empty($up_name) || empty($up_email)) {
header("location: index.php?error=emptyfields");
exit();
}
elseif (!filter_var($up_email,FILTER_VALIDATE_EMAIL) && !preg_match("/^[a-zA-Z 0-9]*$/", $up_name)) {
header("location: index.php?error=invalidEN&UN=".$up_name);
exit();
}
elseif (!filter_var($up_email,FILTER_VALIDATE_EMAIL)) {
header("location: index.php?error=invalidEN&UN=".$up_name);
exit();
}
elseif (!preg_match("/^[a-zA-Z 0-9]*$/", $up_name)) {
header("location: index.php?error=invalidName&E=".$up_email);
exit();
}
else{
$sql = "SELECT * FROM admin WHERE admin_email=?";
$result = mysqli_stmt_init($conn);
if ( !mysqli_stmt_prepare($result, $sql)){
header("location: index.php?error=sqlerror1");
exit();
}
else{
mysqli_stmt_bind_param($result, "s", $useremail);
mysqli_stmt_execute($result);
$resultl = mysqli_stmt_get_result($result);
if ($row = mysqli_fetch_assoc($resultl)) {
$pwdCheck = password_verify($up_password, $row['admin_pwd']);
if ($pwdCheck == false) {
header("location: index.php?error=wrongpasswordup");
exit();
}
else if ($pwdCheck == true) {
if ($useremail == $up_email) {
$sql = "UPDATE admin SET admin_name=? WHERE admin_email=?";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("location: index.php?error=sqlerror");
exit();
}
else{
mysqli_stmt_bind_param($stmt, "ss", $up_name, $useremail);
mysqli_stmt_execute($stmt);
$_SESSION['Admin-name'] = $up_name;
header("location: index.php?success=updated");
exit();
}
}
else{
$sql = "SELECT admin_email FROM admin WHERE admin_email=?";
$result = mysqli_stmt_init($conn);
if ( !mysqli_stmt_prepare($result, $sql)){
header("location: index.php?error=sqlerror1");
exit();
}
else{
mysqli_stmt_bind_param($result, "s", $up_email);
mysqli_stmt_execute($result);
$resultl = mysqli_stmt_get_result($result);
if (!$row = mysqli_fetch_assoc($resultl)) {
$sql = "UPDATE admin SET admin_name=?, admin_email=? WHERE admin_email=?";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("location: index.php?error=sqlerror");
exit();
}
else{
mysqli_stmt_bind_param($stmt, "sss", $up_name, $up_email, $useremail);
mysqli_stmt_execute($stmt);
$_SESSION['Admin-name'] = $up_name;
$_SESSION['Admin-email'] = $up_email;
header("location: index.php?success=updated");
exit();
}
}
else{
header("location: index.php?error=nouser2");
exit();
}
}
}
}
}
else{
header("location: index.php?error=nouser1");
exit();
}
}
}
}
else{
header("location: index.php");
exit();
}
//*********************************************************************************
?>