forked from Mahekb/GetSpon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignup.php
More file actions
355 lines (289 loc) · 16.2 KB
/
Copy pathSignup.php
File metadata and controls
355 lines (289 loc) · 16.2 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Sign up</title>
<link rel="stylesheet" type="text/css" href="mystyle.css">
<style>
.error {
color: #FF0000;
}
</style>
</head>
<body>
<?php
$uname = $dob = $gender = $username = $phoneno = $email = $password = $cpassword = "";
$checkbox = "";
$city = $state = '--select--';
$unameErr = $genderErr = $cityErr = $stateErr = $dobErr = "";
$userErr = $phoneErr = $emailErr = $passErr = $conpassErr = $cpassErr = $checkboxErr = "";
if (isset($_POST['uname']) && $_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST['uname'])) {
$uname = $_POST["uname"];
if (empty($_POST["uname"])) {
$unameErr = "Name is required";
} else if (!preg_match("/^[a-zA-Z ]*$/", $_POST["uname"])) {
$unameErr = "Only letters are allowed.";
}
}
if (isset($_POST['dateofbirth'])) {
$dob = $_POST["dateofbirth"];
if (empty($_POST["dateofbirth"])) {
$dobErr = "DOB is required";
} else {
$dateob = new DateTime($_POST['dateofbirth']);
$today = new Datetime(date('y.m.d'));
$diff = $today->diff($dateob);
if ($diff->y < 18) {
$dobErr = "You are not eligible.";
}
}
}
if (isset($_POST['city'])) {
$city = $_POST["city"];
if ($_POST['city'] == "--select--") {
$cityErr = "City is required";
}
}
if (isset($_POST['state'])) {
$state = $_POST["state"];
if ($_POST['state'] == "--select--") {
$stateErr = "State is required";
}
}
if (empty($_POST["gender"])) {
$genderErr = "Gender is required";
} else {
$gender = $_POST["gender"];
}
if (isset($_POST['username'])) {
$username = $_POST["username"];
if (empty($_POST["username"])) {
$userErr = "Username is required";
} else if (!preg_match("/^[a-zA-Z0-9]*$/", $_POST["username"])) {
$userErr = "Only letters and numbers are allowed.";
} else {
$conn = mysqli_connect("localhost", "root", "", "Getspon");
if (!$conn) {
die("Connection failed:" . mysqli_connect_error());
}
$stmt = $conn->prepare("SELECT Username FROM user_details WHERE Username=?");
$stmt->bind_param('s', $username);
$stmt->execute();
$result = $stmt->get_result();
if (mysqli_num_rows($result) > 0) {
$userErr = "Username is already taken.";
}
mysqli_close($conn);
}
}
if (isset($_POST['phoneno'])) {
$phoneno = $_POST["phoneno"];
if (empty($_POST["phoneno"])) {
$phoneErr = "Phone number is required";
} else if (!preg_match("/\d{10}/", $_POST["phoneno"])) {
$phoneErr = "Invalid Phone number.";
} else {
$conn = mysqli_connect("localhost", "root", "", "Getspon");
if (!$conn) {
die("Connection failed:" . mysqli_connect_error());
}
$stmt = $conn->prepare("SELECT Username FROM user_details WHERE Phoneno=?");
$stmt->bind_param('i', $phoneno);
$stmt->execute();
$result = $stmt->get_result();
if (mysqli_num_rows($result) > 0) {
$phoneErr = "Phone number is already in use.";
}
mysqli_close($conn);
}
}
if (isset($_POST['email'])) {
$email = $_POST["email"];
if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else if (!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
} else {
$conn = mysqli_connect("localhost", "root", "", "Getspon");
if (!$conn) {
die("Connection failed:" . mysqli_connect_error());
}
$stmt = $conn->prepare("SELECT Username FROM user_details WHERE Email=?");
$stmt->bind_param('s', $email);
$stmt->execute();
$result = $stmt->get_result();
if (mysqli_num_rows($result) > 0) {
$emailErr = "Email address is already in use.";
}
mysqli_close($conn);
}
}
if (isset($_POST['password'])) {
$password = $_POST["password"];
if (empty($_POST["password"])) {
$passErr = "Password is required";
} else if (!preg_match("/[A-Z]{1,}/", $_POST["password"])) {
$passErr = "Atleast one uppercase letter is required in password.";
} else if (!preg_match("/[a-z]{1,}/", $_POST["password"])) {
$passErr = "Atleast one lowercase letter is required in password.";
} else if (!preg_match("/[0-9]{1,}/", $_POST["password"])) {
$passErr = "Atleast one numeric value is required in password.";
} else if (!preg_match("/(\W{1,}|[_]{1,})/", $_POST["password"])) {
$passErr = "Atleast one special character is required in password.";
} else if (preg_match("/[ ]{1,}/", $_POST["password"])) {
$passErr = "Spaces are not allowed in password.";
} else {
}
}
if (isset($_POST['cpassword'])) {
$cpassword = $_POST["cpassword"];
if (empty($_POST["cpassword"])) {
$conpassErr = "Password needs to be entered again.";
} else if ($_POST['password'] != $_POST['cpassword']) {
$conpassErr = "Passwords should be same.";
}
}
if (!empty($_POST["checkbox"])) {
$checkbox = $_POST['checkbox'];
}
if (empty($_POST["checkbox"])) {
$checkboxErr = "Terms and conditions needs to be agreed.";
}
if ($unameErr == "" && $genderErr == "" && $cityErr == "" && $stateErr == "" && $dobErr == "" && $userErr == "" && $phoneErr == "" && $emailErr == "" && $passErr == "" && $conpassErr == "" && $checkboxErr == "" && $cpassErr == "") {
$conn = mysqli_connect("localhost", "root", "", "Getspon");
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$query = "INSERT INTO user_details VALUES (?,?,?,?,?,?,?,?,?)";
$pst = mysqli_prepare($conn, $query);
$password1 = password_hash($password, PASSWORD_DEFAULT);
mysqli_stmt_bind_param($pst, "ssssssiss", $uname, $dob, $city, $state, $gender, $username, $phoneno, $email, $password1);
mysqli_stmt_execute($pst);
$getResult = mysqli_stmt_get_result($pst);
mysqli_stmt_close($pst);
$conn->close();
header("Location: Login.php");
exit;
}
}
?>
<ul>
<li><a class="left"><img src="Images/Mainlogo.jpg" width="100" </a></li>
<li><a class="left" href="Home_page.php">Home</a></li>
<li><a class="left" href="#About">About</a></li>
<li><a class="left" href="#Contact">Contact</a></li>
<li><a class="right" href="Login.php">Log in</a></li>
</ul><br><br>
<div align="center" id="reg">
<h1>Register Here</h1><br>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
Name:
<input type="text" name="uname" class="input-box" value="<?php echo $uname ?>" placeholder="First_Name Last_Name" maxlength="40">
<?php
if ($unameErr != "") {
echo '<br/> <span class="error">*' . $unameErr . '</span>';
}
?>
<br><br>
Date of Birth:
<input type="date" name="dateofbirth" class="input-box" value="<?php echo $dob ?>">
<?php
if ($dobErr != "") {
echo '<br/> <span class="error">*' . $dobErr . '</span>';
}
?>
<br><br>
City:
<select name="city" class="input-box" size=1 value="<?php echo $city ?>">
<option value="<?php echo $city ?>"><?php echo $city ?></option>
<option value="Mumbai">Mumbai</option>
<option value="Pune">Pune</option>
<option value="Bangalore">Bangalore</option>
<option value="Delhi">Delhi</option>
</select>
<?php
if ($cityErr != "") {
echo '<br/> <span class="error">*' . $cityErr . '</span>';
}
?>
<br><br>
State:
<select name="state" class="input-box" size=1 value="<?php echo $state ?>">
<option value="<?php echo $state ?>"><?php echo $state ?></option>
<option value="Gujarat">Gujarat</option>
<option value="Maharashtra">Maharashtra</option>
<option value="Punjab">Punjab</option>
<option value="Rajasthan">Rajasthan</option>
<option value="Tamil Nadu">Tamil Nadu</option>
</select>
<?php
if ($stateErr != "") {
echo '<br/> <span class="error">*' . $stateErr . '</span>';
}
?>
<br><br>
Gender:
<input type="radio" name="gender" value="male" <?php if ($gender == 'male') echo 'checked' ?>> Male
<input type="radio" name="gender" value="female" <?php if ($gender == 'female') echo 'checked' ?>> Female
<input type="radio" name="gender" value="other" <?php if ($gender == 'other') echo 'checked' ?>> Other
<?php
if ($genderErr != "") {
echo '<br/> <span class="error">*' . $genderErr . '</span>';
}
?>
<br><br>
Username:
<input type="text" name="username" class="input-box" value="<?php echo $username ?>" minlength="6" maxlength="20">
<?php
if ($userErr != "") {
echo '<br/> <span class="error">*' . $userErr . '</span>';
}
?>
<br><br>
Phone no:
<input type="text" name="phoneno" class="input-box" value="<?php echo $phoneno ?>">
<?php
if ($phoneErr != "") {
echo '<br/> <span class="error">*' . $phoneErr . '</span>';
}
?>
<br><br>
Email:
<input type="text" name="email" placeholder="username@gmail.com" class="input-box" value="<?php echo $email ?>" maxlength="30">
<?php
if ($emailErr != "") {
echo '<br/> <span class="error">*' . $emailErr . '</span>';
}
?>
<br><br>
Password:
<input type="password" name="password" class="input-box" placeholder="Create a strong password" value="<?php echo $password ?>" minlength="7" maxlength="30">
<?php
if ($passErr != "") {
echo '<br/> <span class="error">*' . $passErr . '</span>';
}
?>
<br><br>
Confirm password:
<input type="password" name="cpassword" class="input-box" placeholder="Make sure to enter the same password" value="<?php echo $cpassword ?>">
<?php
if ($conpassErr != "") {
echo '<br/> <span class="error">*' . $conpassErr . '</span>';
}
?>
<br><br>
<Text>By creating an account you agree to our <sa href="#">Terms & Privacy</sa>.</Text><br><br>
<input type="checkbox" name="checkbox" value="checkbox" <?php if ($checkbox == 'checkbox') echo 'checked' ?>>
I agree to the terms and conditions.
<?php
if ($checkboxErr != "") {
echo '<br/> <span class="error">*' . $checkboxErr . '</span>';
}
?>
<br><br>
<input class="reset-button" type="reset" value="Reset">
<input class="submit-button" type="submit" value="Register">
</form>
</div>
</body>
</html>