-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_admin.php
More file actions
161 lines (147 loc) · 4.79 KB
/
add_admin.php
File metadata and controls
161 lines (147 loc) · 4.79 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
session_start();
include 'databaseconnection.php';
if (!isset($_SESSION['admin_user'])) {
header('Location: admin.php');
exit();
}
$message = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = mysqli_real_escape_string($conn, $_POST['username']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
$country_of_work = mysqli_real_escape_string($conn, $_POST['country_of_work']);
$sql = "SELECT * FROM admin_users WHERE username = '$username'";
$result = mysqli_query($conn, $sql);
if ($result && mysqli_num_rows($result) > 0) {
$message = "Username already exists. Please choose another.";
} else {
// Hashing password
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
// Inserting admin database
$sql = "
INSERT INTO admin_users (username, password, country_of_work)
VALUES ('$username', '$hashed_password', '$country_of_work')
";
if (mysqli_query($conn, $sql)) {
$message = "Admin user added successfully!";
} else {
$message = "Error adding admin user: " . mysqli_error($conn);
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Add Admin User</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
margin: 0;
padding: 0;
}
.container {
max-width: 400px;
margin: 50px auto;
padding: 20px;
background-color: white;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
h2 {
text-align: center;
color: crimson;
}
form {
display: flex;
flex-direction: column;
gap: 15px;
}
label {
font-weight: bold;
color: darkblue;
}
input {
padding: 10px;
border-radius: 5px;
border: 1px solid #ccc;
font-size: 16px;
}
button {
background-color: crimson;
color: white;
padding: 12px;
font-size: 16px;
font-weight: bold;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: darkred;
}
.message {
text-align: center;
margin-top: 10px;
font-weight: bold;
}
.message.success {
color: green;
}
.message.error {
color: red;
}
header {
background-color: darkblue;
color: white;
padding: 15px 20px;
display: flex;
justify-content: space-between;
align-items: center;
}
header a {
color: white;
text-decoration: none;
font-weight: bold;
}
header a:hover {
text-decoration: underline;
}
.banner {
width: 105%;
max-height:252px ;
object-fit: cover;
}
</style>
</head>
</style>
</head>
<header style="background-color: darkblue ; color: white; padding: 10px 20px; display: flex; justify-content: space-between; align-items: center;">
<div style="font-size: 24px; font-weight: bold;"><a href="index.html" >Visa Application System</a></div>
<div>
<a href="dashboard.php" style="color: white; text-decoration: none; margin-right: 20px;">Return</a>
<a href="logout.php" style="color: white; text-decoration: none;">Log Out</a>
</div>
</header>
<img src="banner.png"our banner" class="banner">
<body>
<div class="container">
<h2>Add Admin User</h2>
<form method="POST">
<label for="username">Username:</label>
<input type="text" id="username" name="username" placeholder="Enter username" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" placeholder="Enter password" required>
<label for="country_of_work">Country of Work:</label>
<input type="text" id="country_of_work" name="country_of_work" placeholder="Enter country of work" required>
<button type="submit">Add Admin</button>
</form>
<?php if ($message): ?>
<div class="message <?= strpos($message, 'successfully') !== false ? 'success' : 'error'; ?>">
<?= htmlspecialchars($message); ?>
</div>
<?php endif; ?>
</div>
</body>
</html>