-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateUser.php
139 lines (130 loc) · 3.62 KB
/
createUser.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
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
<?php include "../inc/dbinfo.inc"; ?>
<!DOCTYPE html>
<html>
<head>
<title>User Registration</title>
<style>
body {
background-color: #F2F2F2;
}
h2 {
text-align: center;
}
form {
background-color: white;
border: 2px solid #F2F2F2;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
margin: 50px auto;
padding: 20px;
max-width: 400px;
width: 100%;
}
table {
margin-top: 20px;
margin-bottom: 20px;
width: 100%;
border-collapse: collapse;
}
td {
padding: 10px;
text-align: right;
vertical-align: middle;
border-bottom: 1px solid #ddd;
}
input[type="text"],
input[type="password"] {
border: 1px solid #CCCCCC;
border-radius: 5px;
font-size: 16px;
height: 30px;
padding: 5px;
width: 100%;
}
input[type="submit"] {
background-color: #3e8e41;
border: none;
border-radius: 5px;
color: white;
cursor: pointer;
font-size: 16px;
height: 40px;
margin-top: 10px;
width: 100%;
}
input[type="submit"]:hover {
background-color: #3e8e41;
}
tr:hover {
background-color: #f5f5f5;
}
button {
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
padding: 10px;
border-radius: 5px;
margin-right: 5px;
}
button:hover {
background-color: #3e8e41;
}
</style>
</head>
<body>
<h2>Enter New User Information</h2>
<!-- Input form -->
<form action="<?php echo $_SERVER['SCRIPT_NAME'] ?>" method="POST">
<table>
<tr>
<td><label for="username">Username:</label></td>
<td><input type="text" name="username" id="username"></td>
</tr>
<tr>
<td><label for="password">Password:</label></td>
<td><input type="password" name="password" id="password"></td>
</tr>
<tr>
<td><label for="password">Re-type Password:</label></td>
<td><input type="password" name="repassword" id="repassword"></td>
</tr>
<tr>
<td><label for="fullname">Full Name:</label></td>
<td><input type="text" name="fullname" id="fullname"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Create"></td>
</tr>
</table>
<p style="text-align:right">Back to Log In? <a href="https://ec2-54-82-112-252.compute-1.amazonaws.com/login.php">Click Here</a></p>
</form>
<?php
/* Connect to MySQL and select the database. */
$connection = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD);
if (mysqli_connect_errno()) echo "Failed to connect to MySQL: " . mysqli_connect_error();
$database = mysqli_select_db($connection, DB_DATABASE);
$username = htmlentities($_POST['username']);
$password = htmlentities($_POST['password']);
$repassword = htmlentities($_POST['repassword']);
$fullname = htmlentities($_POST['fullname']);
if(strlen($username) && strlen($password) && strlen($repassword) && strlen($fullname)) {
if (strcmp($password,$repassword)===0) {
$us = mysqli_real_escape_string($connection, $username);
$pa = mysqli_real_escape_string($connection, $password);
$re = mysqli_real_escape_string($connection, $repassword);
$fu = mysqli_real_escape_string($connection, $fullname);
$query = "INSERT INTO user_details (username,password,full_name) VALUES ('$us', '$pa','$fu');";
mysqli_query($connection,$query);
header("Location: login.php");
} else {
echo "<script>alert('Your password does not match! Please try it again!');</script>";
}
}
?>
<!-- Clean up. -->
<?php
mysqli_free_result($result);
mysqli_close($connection);
?>
</body>
</html>