-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_signup.php
More file actions
404 lines (366 loc) · 13.8 KB
/
user_signup.php
File metadata and controls
404 lines (366 loc) · 13.8 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
<?php
// Include the database connection
$servername = "localhost"; // or your server IP
$username = "root"; // your database username
$password = ""; // your database password
$dbname = "print_management"; // your database name
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Get the form data
$name = $_POST['name']; // Get the name
$email = $_POST['email'];
$password = $_POST['password'];
$confirmPassword = $_POST['confirmPassword'];
// Validate input data
$errors = [];
// Check if name is valid
if (empty($name)) {
$errors[] = "Name is required.";
}
// Check if email is valid
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = "Invalid email address.";
}
// Check if password is at least 8 characters
if (strlen($password) < 8) {
$errors[] = "Password must be at least 8 characters long.";
}
// Check if passwords match
if ($password !== $confirmPassword) {
$errors[] = "Passwords do not match.";
}
// If there are no errors, proceed to insert the data
if (empty($errors)) {
// Hash the password for security
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
// Prepare the SQL query to insert the user data into the database
$query = "INSERT INTO users (name, email, password) VALUES (?, ?, ?)"; // Include name in the query
$stmt = $conn->prepare($query);
// Bind the parameters and execute the statement
if ($stmt->bind_param("sss", $name, $email, $hashedPassword)) {
$stmt->execute();
// Check if the insertion was successful
if ($stmt->affected_rows > 0) {
$successMessage = "Sign-up successful! You can now <a href='login_user.php'>login</a>.";
} else {
$errorMessage = "There was an error during sign-up. Please try again.";
}
$stmt->close();
} else {
$errorMessage = "There was an error in preparing the statement.";
}
} else {
// Collect validation errors
$errorMessage = implode('<br>', $errors);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Sign Up Page</title>
<style>
body {
background-image: url('photo.jpg');
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
}
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
width: 100%;
}
.form {
height: auto;
width: 300px;
border: 2px solid pink;
padding: 20px;
box-shadow: 2px 6px pink;
display: flex;
flex-direction: column;
background: rgba(255, 255, 255, 0.2);
backdrop-filter: blur(10px);
border: 0px solid rgba(255, 255, 255, 0.3);
}
.form label {
margin-bottom: 5px;
font-weight: bold;
color: #333;
margin-left:5px;
font-family:'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
}
.form input[type="text"],
.form input[type="password"],
.form input[type="email"] {
margin-bottom: 25px;
padding: 10px;
border: 1px solid #ccc;
border-radius:12px;
font-size: 16px;
}
.form input[type="submit"] {
padding: 10px;
border: none;
border-radius: 12px;
background-color: #ff69b4;
color: white;
font-size: 16px;
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
cursor: pointer;
transition: background-color 0.3s;
}
.form input[type="submit"]:hover {
background-color: #ff1493;
}
.form a {
text-align: center;
display: block;
margin-top: 5px;
color: #ff69b4;
text-decoration: none;
transition: color 0.3s;
}
.form a:hover {
color: #ff1493;
}
.form .error {
color: red;
font-size: 14px;
}
.form .success {
color: green;
font-size: 14px;
}
.tab-container {
display: flex;
justify-content: space-around;
margin-bottom: 20px;
}
.tab {
width: 50%;
padding: 10px;
text-align: center;
border-radius: 20px;
}
.tab.active {
background-color: #a600d8;
color: white;
margin-left:4px;
}
.tab.inactive {
background-color: #ffffff;
color: #a600d8;
border: 1px solid #a600d8;
}
</style>
</head>
<body>
<h1 style="font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;"><center>User Signup Form</center></h1>
<div class="container">
<form class="form" id="signUpForm" action="user_signup.php" method="POST">
<div class="tab-container">
<div class="tab inactive"><a href="./login_user.php" style="text-decoration: none; color: inherit;">Login</a></div>
<div class="tab active">Sign Up</div>
</div>
<label for="name">Name</label> <!-- New name input -->
<input type="text" id="name" name="name" placeholder="Enter Your Name" required>
<span class="error" id="nameError"></span>
<label for="email">Email Address</label>
<input type="email" id="email" name="email" placeholder="Enter Your Email" required>
<span class="error" id="emailError"></span>
<label for="password">Password</label>
<input type="password" id="password" name="password" placeholder="Enter Your Password" required>
<span class="error" id="passwordError"></span>
<label for="confirmPassword">Confirm Password</label>
<input type="password" id="confirmPassword" name="confirmPassword" placeholder="Confirm Your Password" required>
<span class="error" id="confirmPasswordError"></span>
<input type="submit" value="Sign Up">
<?php if (isset($errorMessage)): ?>
<p class="error"><?= $errorMessage; ?></p>
<?php elseif (isset($successMessage)): ?>
<p class="success"><?= $successMessage; ?></p>
<?php endif; ?>
</form>
</div>
</body>
</html>
<!-- <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Sign Up Page</title>
<style>
body {
background-image: url('photo.jpg');
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
}
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
width: 100%;
}
.form {
height: auto;
width: 300px;
border: 2px solid pink;
padding: 20px;
box-shadow: 2px 6px pink;
display: flex;
flex-direction: column;
background: rgba(255, 255, 255, 0.2);
backdrop-filter: blur(10px);
border: 0px solid rgba(255, 255, 255, 0.3);
}
.form label {
margin-bottom: 5px;
font-weight: bold;
color: #333;
margin-left:5px;
font-family:'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
}
.form input[type="text"],
.form input[type="password"],
.form input[type="email"] {
margin-bottom: 25px;
padding: 10px;
border: 1px solid #ccc;
border-radius:12px;
font-size: 16px;
}
.form input[type="submit"] {
padding: 10px;
border: none;
border-radius: 12px;
background-color: #ff69b4;
color: white;
font-size: 16px;
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
cursor: pointer;
transition: background-color 0.3s;
}
.form input[type="submit"]:hover {
background-color: #ff1493;
}
.form a {
text-align: center;
display: block;
margin-top: 5px;
color: #ff69b4;
text-decoration: none;
transition: color 0.3s;
}
.form a:hover {
color: #ff1493;
}
.form .error {
color: red;
font-size: 14px;
}
.tab-container {
display: flex;
justify-content: space-around;
margin-bottom: 20px;
}
.tab {
width: 50%;
padding: 10px;
text-align: center;
border-radius: 20px;
}
.tab.active {
background-color: #a600d8;
color: white;
margin-left:4px;
}
.tab.inactive {
background-color: #ffffff;
color: #a600d8;
border: 1px solid #a600d8;
}
</style>
</head>
<body>
<h1 style="font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;"><center>User Signup Form</center></h1>
<div class="container">
<form class="form" id="signUpForm" onsubmit="return validateForm()">
<div class="tab-container">
<div class="tab inactive"><a href="./login_user.html" style="text-decoration: none; color: inherit;">Login</a></div>
<div class="tab active">Sign Up</div>
</div>
<!-- <label for="username">Username</label>
<input type="text" id="username" name="username" placeholder="Enter The Username" required>
<span class="error" id="usernameError"></span> -->
<!-- <label for="email">Email Address</label>
<input type="email" id="email" name="email" placeholder="Enter The Email" required>
<span class="error" id="emailError"></span>
<label for="password">Password</label>
<input type="password" id="password" name="password" placeholder="Enter The Password" required>
<span class="error" id="passwordError"></span>
<label for="confirmPassword">Confirm Password</label>
<input type="password" id="confirmPassword" name="confirmPassword" placeholder="Confirm The Password" required>
<span class="error" id="confirmPasswordError"></span>
<input type="submit" value="Sign Up">
</form>
</div>
<script>
function validateForm() {
// var username = document.getElementById('username').value;
var email = document.getElementById('email').value;
var password = document.getElementById('password').value;
var confirmPassword = document.getElementById('confirmPassword').value;
// var usernameError = document.getElementById('usernameError');
var emailError = document.getElementById('emailError');
var passwordError = document.getElementById('passwordError');
var confirmPasswordError = document.getElementById('confirmPasswordError');
var isValid = true; -->
<!-- // Username validation
// if (username.length < 5) {
// usernameError.textContent = 'Username must be at least 5 characters long.';
// isValid = false;
// } else {
// usernameError.textContent = '';
// }
// Email validation
var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailPattern.test(email)) {
emailError.textContent = 'Please enter a valid email address.';
isValid = false;
} else {
emailError.textContent = '';
}
// Password validation
if (password.length < 8) {
passwordError.textContent = 'Password must be at least 8 characters long.';
isValid = false;
} else {
passwordError.textContent = '';
}
// Confirm Password validation
if (password !== confirmPassword) {
confirmPasswordError.textContent = 'Passwords do not match.';
isValid = false;
} else {
confirmPasswordError.textContent = '';
}
return isValid;
}
</script>
</body>
</html> --> -->