-
Notifications
You must be signed in to change notification settings - Fork 0
/
deleteUser.php
128 lines (101 loc) · 2.92 KB
/
deleteUser.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
<?php
//Redirects login if not signed in
if(isset($_COOKIE['Status']) && $_COOKIE['Status'] == "LoggedIn"){ }
else{
header("Location:index.php");
}
?>
<?php
include("PHPconnectionDB.php");
//Checks to see if a username exists
function validUserName ($username) {
$sql = 'SELECT *
FROM users
WHERE user_name = \''.$username.'\'';
$conn = connect();
$stid = oci_parse($conn, $sql);
$res=oci_execute($stid, OCI_DEFAULT);
if (!$res) {
$err = oci_error($stid);
echo htmlentities($err['message']);
}
$row = oci_fetch_array($stid, OCI_ASSOC);
//If no username is found
if($row == NULL){
header("location:admin.php?dError=invalidUsername");
exit();
}
}
//Delete a user is clicked
if(isset($_POST["submitDeleteUser"])){
$username = $_POST["deleteUsername"];
//Checks if the username exists
validUserName($username);
//Statement to delete the user
$conn = connect();
$sql = 'DELETE FROM users WHERE (user_name = \''.$username.'\')';
$stid = oci_parse($conn, $sql);
$res=oci_execute($stid, OCI_DEFAULT);
//Return with error on failure
if (!$res) {
$err = oci_error($stid);
echo htmlentities($err['message']);
header("location:admin.php?dError=general");
exit();
}
$res = oci_commit($conn);
//Return on success
header("location:admin.php?dSuccess=user");
exit();
//If deleting a person is clicked
} elseif(isset($_POST["submitDeletePerson"])){
$email = $_POST["deleteEmail"];
//Get the person with the email
$sql = 'SELECT *
FROM persons
WHERE email = \''.$email.'\'';
$conn = connect();
$stid = oci_parse($conn, $sql);
$res=oci_execute($stid, OCI_DEFAULT);
//Return with error on failure
if (!$res) {
$err = oci_error($stid);
echo htmlentities($err['message']);
header("location:admin.php?dError=general");
exit();
}
$row = oci_fetch_array($stid, OCI_ASSOC);
//If no rows were found it is an invalid email
if($row == NULL){
header("location:admin.php?error=invalidEmail");
exit();
}
//Deleting the user associated with the email
$pid = $row["PERSON_ID"];
$sql = 'DELETE FROM users WHERE (person_id = \''.$pid.'\')';
$stid = oci_parse($conn, $sql);
$res=oci_execute($stid, OCI_DEFAULT);
//Return with error on failure
if (!$res) {
$err = oci_error($stid);
echo htmlentities($err['message']);
header("location:admin.php?dError=general");
exit();
}
$res = oci_commit($conn);
//Deleting the person associated with the email
$sql = 'DELETE FROM persons WHERE (person_id = \''.$pid.'\')';
$stid = oci_parse($conn, $sql);
$res=oci_execute($stid, OCI_DEFAULT);
if (!$res) {
$err = oci_error($stid);
echo htmlentities($err['message']);
header("location:admin.php?dError=general");
exit();
}
$res = oci_commit($conn);
//Return with success
header("location:admin.php?dSuccess=person");
exit();
}
?>