-
Notifications
You must be signed in to change notification settings - Fork 0
/
policeofficer_createaccount.php
64 lines (60 loc) · 1.86 KB
/
policeofficer_createaccount.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
<html>
<head>
<title>Police Officer Information</title>
<meta http-equiv="Content-type" content="text/html;charset=utf-8">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<?php
include('connection.php');
include('topnav.php');
?>
<h2>Add new police officer account</h2>
<form class="box1" action="" method="POST">
<input type="text" name="username" placeholder="Police officer username" required/><br>
<input type="password" name="password" placeholder="Police officer password" required/><br>
<input type="password" name="confirmpassword" placeholder="Confirm password" required/><br>
<input type="Submit" value="Add account"/>
</form>
<?php
// Check connection
if(mysqli_connect_errno())
{
echo "Failed to connect to MySQL: ".mysqli_connect_error();
die();
}
else
{
if ($_POST['username']!="" && $_POST['password']!="" && $_POST['confirmpassword']!="")
{
// Check username existence
$sql = "SELECT * FROM Users WHERE Username='".$_POST['username']."'";
$result = mysqli_query($conn, $sql);
$num_rows = mysqli_num_rows($result);
if ($num_rows != 0)
{
function_alert("This username already exists!");
}
else
{
if ($_POST['password'] == $_POST['confirmpassword'])
{
// Add new account to table Users
$sql = "INSERT INTO Users VALUES ('".$_POST['username']."','".$_POST['password']."')";
$result = mysqli_query($conn, $sql);
function_alert("New police officer account added successfully!");
}
else
{
function_alert("Your confirmation for the password is incorrect. Please try again!");
}
}
}
}
mysqli_close($conn);
function function_alert($msg) {
echo "<script type='text/javascript'>alert('$msg');</script>";
}
?>
</body>
</html>