-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreg.php
More file actions
78 lines (75 loc) · 2.37 KB
/
reg.php
File metadata and controls
78 lines (75 loc) · 2.37 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
<?php
if(isset($_POST['reg']))
{
//Connecting
require 'connection.php';
/*Registering */
$name = $_POST['name'];
$username = $_POST['username'];
$email = $_POST['email'];
$dob = date('Y-m-d', strtotime($_POST['dob']));
//$dob = $_POST['dob']; ---Alternate method
$pass1 = $_POST['pwd'];
$pass2 = $_POST['pwd1'];
$gender = $_POST['gender'];
$type = 0;
//Checking for Errors
if(empty($name) || empty($username) || empty($email) || empty($dob) || empty($pass1) || empty($pass2))
{
header("Location: register.php?error=emptyfields&name=".$name."&username=".$username."&email=".$email."&dob=".$dob);
exit();
}
// else if (!preg_match("/^[a-zA-Z]*$/", $name)) {
// header("Location: register.php?error=invalidname&username=".$username."&email=".$email."&dob=".$dob);
// exit();
// }
else if (!preg_match("/^[a-zA-Z0-9]*$/", $username)) {
header("Location: register.php?error=invalidusername&name=".$name."&email=".$email."&dob=".$dob);
exit();
}
else if ($pass1 !== $pass2) {
header("Location: register.php?error=passwordnotmatch&name=".$name."&username=".$username."&email=".$email."&dob=".$dob);
exit();
}
else
{
$sql = "SELECT uname from users where uname=? OR email=?";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: register.php?error=sqlerror");
exit();
}
else {
mysqli_stmt_bind_param($stmt, "ss", $username, $email);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
$resultCheck = mysqli_stmt_num_rows($stmt);
if($resultCheck > 0)
{
header("Location: register.php?error=usernameoremailtaken");
exit();
}
else {
$sql = "INSERT INTO users (name, uname, email, dob, password, type, gender) values(?,?,?,?,?,?,?)";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: register.php?error=sqlerror");
exit();
}
else {
$hashedpass = password_hash($pass1, PASSWORD_DEFAULT);
mysqli_stmt_bind_param($stmt, "sssssis", $name, $username, $email, $dob, $hashedpass, $type, $gender);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
header("Location: login.php?status=success");
exit();
}
}
}
}
mysqli_stmt_close($stmt);
mysqli_close($conn);
}
else
header("Location: register.php");
?>