-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_remove_admin_code.php
More file actions
77 lines (72 loc) · 2.13 KB
/
admin_remove_admin_code.php
File metadata and controls
77 lines (72 loc) · 2.13 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
<?php
// Process delete operation after confirmation
session_start();
$adid = $_POST['adid'];
if(!empty($adid)){
// Include configuration
$host = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbName = "museumsys";
// create connection
$link = new mysqli($host, $dbUsername, $dbPassword, $dbName);
// Prepare a delete statement
$DELETE = "DELETE FROM admin WHERE ad_id = ? LIMIT 1";
if(mysqli_connect_error()){
die('Connect Error(' . mysqli_connect_errno().')'.mysqli_connect_error());
}
else{
//Check if id is super id or not
if($adid != 'super'){
//Prepare a select statement to check after excute delete
$SELECT = "SELECT ad_id FROM admin WHERE ad_id = ? LIMIT 1";
//checking if id exists or not
$stmt = $link->prepare($SELECT);
$stmt->bind_param("s", $adid);
$stmt->execute();
$stmt->bind_result($staffid);
$stmt->store_result();
$rnum = $stmt->num_rows;
$stmt->close();
if($rnum==0){
$_SESSION['msg'] = "<script>window.alert('No such ID exists')</script>";
header("location: admin_menu.php");
}
else{
//now delete legally
//executing delete
$dtmt = $link->prepare($DELETE);
$dtmt->bind_param("s", $adid);
$dtmt->execute();
//after delete check if any row of staff_id exists or not
//execute select
$dtmt->close();
$stmt = $link->prepare($SELECT);
$stmt->bind_param("s", $adid);
$stmt->execute();
$stmt->bind_result($adid);
$stmt->store_result();
$rnum = $stmt->num_rows;
if($rnum!=0){
$_SESSION['msg'] = "<script>window.alert('Delete unsuccessful. Try again')</script>";
header("location: admin_menu.php");
}
else{
$_SESSION['msg'] = "<script>window.alert('Delete successful')</script>";
header("location: admin_menu.php");
}
$stmt->close();
$link->close();
}
}else{
$_SESSION['msg'] = "<script>window.alert('Cannot remove super admin')</script>";
header("location: admin_menu.php");
}
}
} else{
//check if id is present or not
$_SESSION['msg'] = "<script>window.alert('Enter a ID to remove')</script>";
die();
header("location: admin_menu.php");
}
?>