-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
121 lines (105 loc) · 3.5 KB
/
register.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
<?php
// Check if the user is already logged in, redirect to another page if true
session_start();
if (isset($_SESSION['user_id'])) {
header("Location: ../login.php"); // Replace 'login.php' with the page you want to redirect to
exit();
}
// Display error message if provided in the URL
$error = isset($_GET['error']) ? $_GET['error'] : "";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Registration</title>
<style>
body {
font-family: 'Arial', sans-serif;
background-color: #f4f4f4;
text-align: center;
margin: 50px;
}
h2 {
color: #333;
}
form {
max-width: 400px;
margin: 0 auto;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
label {
display: block;
margin-bottom: 8px;
}
input {
width: 100%;
padding: 8px;
margin-bottom: 16px;
box-sizing: border-box;
}
button {
background-color: #4caf50;
color: white;
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
}
p.error {
color: red;
margin-top: 10px;
}
</style>
</head>
<body>
<h2>User Registration</h2>
<a href="../login.php" style="display: inline-block; background-color: #4caf50; color: white; padding: 10px 15px; border: none; border-radius: 4px; cursor: pointer; text-decoration: none; margin-top: 10px;">Home</a>
<br><br>
<form action="config/register_process.php" method="post" onsubmit="return validateForm()">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="password">Password (minimum 8 characters):</label>
<input type="password" id="password" name="password" required>
<button type="submit">Register</button>
<?php
if (isset($_GET['error'])) {
$error = $_GET['error'];
if ($error === 'username_taken') {
echo '<p class="error">Username already taken. Please choose a different one.</p>';
} elseif ($error === 'email_taken') {
echo '<p class="error">Email already taken. Please use a different one.</p>';
} elseif ($error === 'database_error') {
echo '<p class="error">Error in database insertion. Please try again later.</p>';
}
}
?>
</form>
<script>
function validateForm() {
var password = document.getElementById("password").value;
if (password.length < 8) {
alert("Password must be at least 8 characters long.");
return false;
}
return true;
}
// Function to clear all form fields after 1 second
function clearFormFields() {
// Your existing clearFormFields function remains unchanged
}
// Call the function when the document is fully loaded
document.addEventListener('DOMContentLoaded', function () {
clearFormFields();
});
</script>
</body>
</html>