-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistration form
80 lines (66 loc) · 2.14 KB
/
registration form
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
<!DOCTYPE html>
<html>
<head>
<title>Registration Form</title>
</head>
<body>
<h2>Registration Form</h2>
<form method="post" action="register.php">
<label for="first_name">First Name:</label>
<input type="text" id="first_name" name="first_name" required><br><br>
<label for="last_name">Last Name:</label>
<input type="text" id="last_name" name="last_name" required><br><br>
<label for="email">Email Address:</label>
<input type="email" id="email" name="email" required><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br><br>
<label for="confirm_password">Confirm Password:</label>
<input type="password" id="confirm_password" name="confirm_password" required><br><br>
<input type="submit" value="Register">
</form>
</body>
</html>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$password = $_POST['password'];
$confirm_password = $_POST['confirm_password'];
// Validate the form fields
$errors = array();
if (empty($first_name)) {
$errors[] = "First name is required.";
}
if (empty($last_name)) {
$errors[] = "Last name is required.";
}
if (empty($email)) {
$errors[] = "Email address is required.";
} else if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = "Invalid email address format.";
}
if (empty($password)) {
$errors[] = "Password is required.";
}
if (empty($confirm_password)) {
$errors[] = "Confirm password is required.";
} else if ($password !== $confirm_password) {
$errors[] = "Passwords do not match.";
}
// If there are no errors, insert the user into the database
if (count($errors) == 0) {
// Insert user into the database
// ...
// Display a success message
echo "Registration successful!";
} else {
// If there are errors, display them on the registration form
echo "<ul>";
foreach ($errors as $error) {
echo "<li>$error</li>";
}
echo "</ul>";
}
}
?>