-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
75 lines (58 loc) · 2.23 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
<?php
include("login.php");
switch($_POST['action']) {
case 'CheckEmail':
$emailReg = $_POST['email'];
CheckEmail($emailReg);
break;
case 'Register':
$emailReg = $_POST['email'];
$user_name = $_POST['username'];
$pass = $_POST['password'];
$cat = $_POST['category'];
$cat_ID = $_POST['categoryId'];
Register($user_name, $emailReg, $pass, $cat, $cat_ID);
break;
default:
// unknown / missing action
}
function CheckEmail($email){
$conn = OpenCon();
$emailQuery = "SELECT email FROM `User` WHERE email = '$email'";
$emailResults = mysqli_query($conn, $emailQuery);
if (mysqli_num_rows($emailResults) > 0) { //email already exists
$val = 1;
echo $val;
return $val;
} else {
$val = 0;
echo $val;
return $val;
}
CloseCon($conn);
}
function Register($username, $email, $password, $category, $categoryId) {
include("classes/user.class.php");
$conn = OpenCon();
$emailQuery = "INSERT INTO User (username, email, password, userCategory, categoryId) VALUES ('$username', '$email', '$password', '$category', '$categoryId')";
if(mysqli_query($conn, $emailQuery)){ //Record added successfully
$last_id = $conn->insert_id;
$user = new User(htmlspecialchars($last_id));
$user->setUsername(htmlspecialchars($username));
$user->setEmail(htmlspecialchars($email));
$user->setPassword(htmlspecialchars($password));
$user->setCategory(htmlspecialchars($category));
$user->setCategoryId(htmlspecialchars($categoryId));
$user->setUniName(htmlspecialchars(null));
$user->setUniDepartment(htmlspecialchars(null));
setcookie('user', serialize($user), time() + 360000, "/" );
$val = 1;
echo $val;
return $val;
} else{
debug_to_console("ERROR: Could not able to execute $sql. " . mysqli_error($conn));
}
// Close connection
CloseCon($conn);
}
?>