-
Notifications
You must be signed in to change notification settings - Fork 0
/
registration_functionality.php
112 lines (89 loc) · 2.17 KB
/
registration_functionality.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
<?php
//include_once 'db_connection.php';
/*
$sql = "SELECT Email FROM Users";
$email_check = $conn->query($sql);
$isTakenF = false;
$name = $pass = $email = "";
$nameErrF = $emailErrF = $passErrF = "";
$countOfSuccesfulFieldsF = 0;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
session_start();
*/
// Name
if (empty($_POST["name"])) {
$nameErrF = "First name is required";
} else {
$name = test_input($_POST["name"]);
//$_SESSION["inputNameF"] = $name;
$countOfSuccesfulFieldsF ++;
}
// PASS
if (empty($_POST["pass"])) {
$passErrF = "Empty field";
} else{
$countOfSuccesfulFieldsF ++;
}
// PASS2
if (empty($_POST["pass2"])) {
$passErrF = "Empty field";
}
else if($_POST["pass2"] != $_POST["pass"])
{
$passErrF = "Do not match";
}
else {
$pass = test_input($_POST["pass"]);
$countOfSuccesfulFieldsF ++;
}
// EMAIL
if (empty($_POST["email"])) {
$emailErrF = "Email is required";
} else if (!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) {/*copied from www.w3school.com */
$emailErrF = "Invalid email format";
}
else{
$email = test_input($_POST["email"]);
while($row = $email_check->fetch_assoc())
{
if($row["Email"] == $email)
$isTakenF = true;
}
if($isTakenF)
{
$emailErrF = "Email has already been taken";
}
else
{
//$_SESSION["email"] = $email;
$countOfSuccesfulFieldsF ++;
}
}
if($countOfSuccesfulFieldsF == 4)
{
$hashPass = password_hash($pass, PASSWORD_DEFAULT);
$insertQuery = "INSERT INTO Users (Name, Email, Pass)
VALUES ('{$name}', '{$email}', '{$hashPass}')";
$_SESSION['loggedIn'] = 0;
if($conn->query($insertQuery) === TRUE)
{
//echo "New record created successfully";
$_SESSION['id'] = $conn->insert_id;
$_SESSION['loggedIn'] = 1;
$_SESSION['name'] = $name;
$_SESSION['email'] = $email;
header('Location: index.php');
}
else
echo "Error";
}//if
/*
}//if
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
*/
?>