-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompanySignupDB.php
142 lines (127 loc) · 4.98 KB
/
companySignupDB.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
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
<?php
class companySignupDB{
private $conn;
public function connect(){
$server_name = 'localhost';
$mysql_user = 'root';
$mysql_password = '';
$database_name = 'SWE';
try {
$this->conn = new PDO("mysql:host=$server_name;dbname=SWE", $mysql_user, $mysql_password);
// set the PDO error mode to exception
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $e)
{
echo "7aram";
echo "Connection failed: " . $e->getMessage();
}
}
public function add($name,$email,$password,$emp,$interest1,$interest2,$interest3,$interest4,$interest5){
echo $interest5;
///insert the user to db
if($this->check_dublicate_register($email)){
return false;
}
if(isset($_POST['submit'])){
$query;
$interest1=$this->check_interest($interest1);
$interest2=$this->check_interest($interest2);
$interest3=$this->check_interest($interest3);
$interest4=$this->check_interest($interest4);
$interest5=$this->check_interest($interest5);
if (!isset($interest1)){
$query = $this->conn->prepare("INSERT INTO company (Name, Password, Email, numOfEmp) VALUES ('$name', '$password', '$email', '$emp')");
}
else if (!isset($interest2)){
$query = $this->conn->prepare("INSERT INTO company (Name, Password, Email, numOfEmp,interest1) VALUES ('$name', '$password', '$email', '$emp','$interest1')");
}
else if (!isset($interest3)){
$query = $this->conn->prepare("INSERT INTO company (Name, Password, Email, numOfEmp,interest1,interest2) VALUES ('$name', '$password', '$email', '$emp','$interest1','$interest2')");
echo "dkhl sah";
}
else if (!isset($interest4)){
$query = $this->conn->prepare("INSERT INTO company (Name, Password, Email, numOfEmp,interest1,interest2,interest3) VALUES ('$name', '$password', '$email', '$emp','$interest1','$interest2','$interest3')");
}
else if (!isset($interest5)){
$query = $this->conn->prepare("INSERT INTO company (Name, Password, Email, numOfEmp,interest1,interest2,interest3,interest4) VALUES ('$name', '$password', '$email', '$emp','$interest1','$interest2','$interest3','$interest4')");
}
else {
echo "hna";
$query = $this->conn->prepare("INSERT INTO company (Name, Password, Email, numOfEmp,interest1,interest2,interest3,interest4,interest5) VALUES ('$name', '$password', '$email', '$emp','$interest1','$interest2','$interest3','$interest4','$interest5')");
}
if ($query->execute()){
$id=$this->getID($email);
session_start();
$_SESSION['ID'] = $id;
header('Location:Home.php?id='.$row['companyID']);
return true;
echo "dakhalloo";
}
}
echo "ghlt";
return false;
}
public function getID($email){
//check if email has registered before
try {
$query = $this->conn->prepare("select companyID from company where Email = '$email' limit 1");
if ($query->execute()){
if ($row = $query->fetch(PDO::FETCH_ASSOC)){
return $row['companyID'];
}
}
}
catch(PDOException $e)
{
echo "7aram";
echo "Connection failed: " . $e->getMessage();
}
}
public function check_dublicate_register($email){
//check if email has registered before
try {
$query = $this->conn->prepare("select * from company where Email = '$email' limit 1");
if ($query->execute()){
if ($row = $query->fetch(PDO::FETCH_ASSOC)){
return true;
}
}
}
catch(PDOException $e)
{
echo "7aram";
echo "Connection failed: " . $e->getMessage();
}
}
public function check_interest($interest){
//check if email has registered before
// $back=NULL;
if (isset($interest)){
try {
$query = $this->conn->prepare("select interestID from interests where interestname = '$interest' limit 1");
if ($query->execute()){
if ($row = $query->fetch(PDO::FETCH_ASSOC)){
return $row['interestID'];
}
else{
$query = $this->conn->prepare("INSERT INTO interests (interestname) VALUES ('$interest')");
if ($query->execute()){
$query = $this->conn->prepare("select interestID from interests where interestname = '$interest' limit 1");
if ($query->execute()){
if ($row = $query->fetch(PDO::FETCH_ASSOC)){
return $row['interestID'];
}
}
}
}
}
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}}
return NULL;
// return $back;
}
}
?>