-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.php
185 lines (167 loc) · 4.96 KB
/
signup.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
// Database connection
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "learningkids";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Registration form handling
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = $_POST["email"];
$password = $_POST["password"];
$role = $_POST["role"];
// Validate email address
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error = "Invalid email address. Please enter a valid email.";
} else {
// Check if email already exists in the database
$sql = "SELECT * FROM users WHERE email = '$email'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$error = "Email address already exists. Please choose a different email.";
} else {
// Validate password
if (strlen($password) > 16 || !preg_match("/[A-Z]/", $password) || !preg_match("/[!@#$%^&*()\-_=+{};:,<.>]/", $password)) {
$error = "Invalid password. Password must be at most 16 characters long and contain at least one capital letter and one symbol.";
} else {
// Insert the user into the database
$sql = "INSERT INTO users (email, password, role) VALUES ('$email', '$password', '$role')";
if ($conn->query($sql) === TRUE) {
// Registration successful, redirect to the login page
header("Location: login.php");
exit();
} else {
// Registration failed, show an error message
$error = "Registration failed. Please try again.";
}
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sign Up | LearningKids</title>
</head>
<style>
body {
font-family: 'Arial', sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
height: 95vh;
}
.signup {
text-align: center;
align-items: center;
justify-content: center;
}
h1 {
color: #333;
text-align: center;
font-weight: 900;
font-size: 40px;
}
form {
width: 100%;
position: relative;
max-width: 500px;
padding: 35px 25px 35px 25px;
background-color: #fff;
border-radius: 16px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
text-align: center;
}
#forming{
text-align: center;
align-items: center;
justify-content: center;
margin-right: 35px;
right: 7.27%;
margin-bottom: 35px;
}
label {
display: block;
margin-bottom: 8px;
color: #333;
}
input {
width: calc(100% - 20px);
padding: 10px;
margin-bottom: 16px;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
}
/* Adjustments for the "Role" field */
label[for="role"] {
display: block;
margin-bottom: 8px;
color: #333;
}
select[name="role"] {
width: calc(100% - 20px);
padding: 10px;
margin-bottom: 25px;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
}
input[type="submit"] {
background-color: #007bff;
color: #fff;
cursor: pointer;
border-radius: 16px;
}
input[type="submit"]:hover {
background-color: #005cbf;
}
p {
margin-top: 10px;
color: #888;
}
a {
color: #007bff;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.error {
color: #d9534f;
margin-bottom: 10px;
}
</style>
<body>
<section class="signup">
<h1>Sign Up</h1>
<?php if (isset($error)) { ?>
<p><?php echo $error; ?></p>
<?php } ?>
<form method="POST" id="forming" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
<label for="email">Email:</label>
<input type="email" name="email" required><br><br>
<label for="password">Password:</label>
<input type="password" name="password" pattern="(?=.*\d)(?=.*[A-Z])(?=.*[!@#$%^&*()\-_=+{};:,<.>]).{1,16}" title="Password must be at most 16 characters long and contain at least one capital letter and one symbol." required><br><br>
<label for="role">Role:</label>
<select name="role" required>
<option value="student">Student</option>
<option value="teacher">Teacher</option>
</select><br><br><br>
<input type="submit" value="Sign Up">
</form>
</section>
</body>
</html>