/
registerUser.php
88 lines (71 loc) · 2.7 KB
/
registerUser.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
<?php
require_once 'DB/initDB.php';
require_once 'DB/registerDB.php';
$rDB= new registerDB();
$redirect = 'register.php';
$fname = htmlspecialchars(trim($_POST['first_name']));
$lname = htmlspecialchars(trim($_POST['last_name']));
$email = mysql_escape_string(trim($_POST['email']));
$sex= mysql_escape_string(trim($_POST['sex']));
$contact= mysql_escape_string(trim($_POST['contact']));
$pass1 = mysql_escape_string(trim($_POST['pass1']));
$pass2 = mysql_escape_string(trim($_POST['pass2']));
$user_type=mysql_escape_string(trim($_POST['user_type']));
$category = mysql_escape_string(trim($_POST['category']));
// $user_name= $_POST['user_name'];
$activated=0;
if(isset($_POST['department'])){
$department = $_POST['department'];
}else{
$department=0; //User is office staff
}
if(isset($_POST['roll_number'])){
$roll_number = $_POST['roll_number'];
}
if(!preg_match('/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/',$email)){
header("Location:/".$redirect."?error=1");
die();
}
if($rDB->checkExistingUser($email)){
header("Location:/".$redirect."?error=2");
die();
}
if(strlen($pass1) < 6) {
header("Location:/".$redirect."?error=3");
die();
}
if($pass1 != $pass2 ) {
header("Location:/".$redirect."?error=4");
die();
}
if($user_type == 0){
header("Location:/".$redirect."?error=5");
die();
}
// if(!preg_match('^[0-9]{10}', $contact)){
// header("Location:/". $redirect."?error=6");
// die();
// }
// if($rDB->checkUserName($user_name)){
// header("Location:/".$redirect."?error=7");
// die();
// }
//For HOD user_type=2
//Faculty Advisor user_type=3
//Office Staff user_type=4
//Student user_type=5
//For Office Staff Department id is equal to 0 that means they don't belong to any department
if($user_type == 2){
$rDB->insertUser($fname,$lname,$user_type,$email,$department,$pass1,$contact,$sex,$activated);
}elseif($user_type == 3){
$rDB->insertUser($fname,$lname,$user_type,$email,$department,$pass1,$contact,$sex,$activated);
}elseif($user_type == 4){
$rDB->insertUser($fname,$lname,$user_type,$email,$department,$pass1,$contact,$sex,$activated);
}elseif($user_type == 5){
$student_id = $rDB->insertUser($fname,$lname,$user_type,$email,$department,$pass1,$contact,$sex,$activated);
if(isset($student_id)){
$rDB->insertStudentInfo($student_id, $roll_number, $category);
}
}
header("Location:done.php?act=1");
?>