-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_registration.php
More file actions
130 lines (120 loc) · 4.05 KB
/
admin_registration.php
File metadata and controls
130 lines (120 loc) · 4.05 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
<?php
session_start();
include 'databaseconnection.php';
$message = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = mysqli_real_escape_string($conn, $_POST['username']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
$confirm_password = mysqli_real_escape_string($conn, $_POST['confirm_password']);
$country_of_work = mysqli_real_escape_string($conn, $_POST['country_of_work']);
// passwords matching
if ($password !== $confirm_password) {
$message = "Passwords do not match.";
} else {
$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);
//insertung in database sql
$sql = "
INSERT INTO admin_users (username, password, country_of_work)
VALUES ('$username', '$hashed_password', '$country_of_work')
";
if (mysqli_query($conn, $sql)) {
$message = "Admin registered successfully!";
} else {
$message = "Error: " . mysqli_error($conn);
}
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Admin Registration</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
margin: 0;
padding: 0;
}
.container {
max-width: 400px;
margin: 100px 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;
}
</style>
</head>
<body>
<div class="container">
<h2>Admin Registration</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="confirm_password">Confirm Password:</label>
<input type="password" id="confirm_password" name="confirm_password" placeholder="Confirm 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">Register Admin</button>
</form>
<?php if ($message): ?>
<div class="message <?= strpos($message, 'successfully') !== false ? 'success' : 'error'; ?>">
<?= htmlspecialchars($message); ?>
</div>
<?php endif; ?>
</div>
</body>
</html>