/
new_admin.php
68 lines (58 loc) · 1.7 KB
/
new_admin.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
<?php include("index.php"); ?>
<?php confirm_logged_in(); ?>
<link rel="stylesheet" type="text/css" href="stylesheets/logon.css">
<?php
// CUSTOMIZE THIS
if (isset($_POST['submit'])) {
// User has submitted a form.
$admins = find_all_admins();
$required_fields = array("username", "password");
validate_presences($required_fields);
if (empty($errors)) {
$username = mysql_prep($_POST["username"]);
$hashed_password = password_encrypt($_POST["password"]);
$query = "INSERT INTO admins (";
$query .= " username, hashed_password";
$query .= ") VALUES (";
$query .= " '{$username}', '{$hashed_password}'";
$query .= ")";
$result = mysqli_query($connection, $query);
if ($result) {
// Success
$_SESSION["message"] = "Admin created.";
redirect_to("events.php");
} else {
// Failure
$_SESSION["message"] = "Admin failed to create.";
redirect_to("events.php");
}
} else {
// Errors exist.
$_SESSION["errors"] = $errors;
redirect_to("new_admin.php");
}
}
?>
<?php echo message(); ?>
<?php $errors = errors(); ?>
<?php echo form_errors($errors); ?>
<table id="logon">
<tr>
<td class="shortrow emphasis">
Create New Admin
</td>
</tr>
<form action="new_admin.php" method="post">
<tr>
<td>Username: <input type="text" name="username"> </td>
</tr>
<tr>
<td>Password: <input type="password" name="password"> </td>
</tr>
<tr>
<td class="shortrow emphasis">
<input type="submit" name="submit" value="Create Admin"/>
</td>
</tr>
</form>
</table>