-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqlFunctions.php
179 lines (161 loc) · 5.68 KB
/
sqlFunctions.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
$GLOBALS['dbcon'] = null;
$dbcon;
function connection(){
global $dbcon;
$host = 'localhost';
$dbname = 'eacademy';
$username = 'root';
$password = '';
// Create connection
try{
$dbcon = new PDO("mysql:host=$host;dbname=$dbname",$username,$password);
$dbcon->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION)."</br>";
$dbcon->setAttribute(PDO::FETCH_BOUND,PDO::FETCH_BOTH);
}catch(PDOException $pdo){
die("Deshtoi lidhja me databazen ($dbname):".$pdo->getMessage());
}
$GLOBALS['dbcon'] = $dbcon;
}
/*
function merrStudentet(){
global $dbcon;
connection();
$sql = "SELECT * FROM students";
$result = $dbcon->query($sql);
return $result;
}
*/
function merrStudentet(){
global $dbcon;
connection();
$sql = "SELECT * FROM students";
$result = mysqli_query($dbcon,$sql);
return $result;
}
function merrInstruktoret(){
global $dbcon;
connection();
$sql = "SELECT * FROM instructors";
$result = $dbcon->query($sql);
return $result;
}
function merrKurset(){
global $dbcon;
connection();
$sql = "SELECT * FROM courses";
$result = $dbcon->query($sql);
return $result;
}
function merrKontaktin(){
global $dbcon;
connection();
$sql = "SELECT * FROM contact";
$result = $dbcon->query($sql);
return $result;
}
function signUp($username,$name,$surname,$email,$password){
global $dbcon;
connection();
$sql = "INSERT INTO students(username,name,surname,email,password) VALUES('$username','$name','$surname','$email','$password')";
$result = $dbcon->query($sql);
if($result){
header("Location: login.php");
return $result;
}
}
/*function login($username,$password){
global $dbcon;
connection();
$sql = "SELECT * FROM students WHERE username = '$username'"; //kshyre tabelen qetu
$result = $dbcon->query($sql); //me instructors
if($result){
if(mysqli_num_rows($result) == 1){
$res = mysqli_fetch_assoc($result);
if(password_verify($password,$res['password'])){
header("Location: courses.php");
session_start();
$_SESSION['studentid'] = $res['studentid'];
$_SESSION['username'] = $res['username'];
$_SESSION['password'] = $res['password'];
return $result;
}else{
echo "<script>alert('Wrong username or password!');</script>";
}
}
}
}*/
/*function signup($name,$surname,$email,$password,$fieldofstudy,$degree,$country){ //become an instructor
connection();
$sql = "INSERT INTO instructors(name,surname,email,password,fieldofstudy,degree,country)";
$sql += " VALUES('$name','$surname','$email','$password','$fieldofstudy','$degree','$country')";
$result = $dbcon->query($sql);
if($result){
header("Location: login.php");
return $result;
}*/
function shtoStudentet($username,$name,$surname,$email,$password){
global $dbcon;
connection();
$sql = "INSERT INTO students(username,name,surname,email,password)";
$sql += " VALUES('$username','$name','$surname','$email','$password')";
$result = $dbcon->query($sql);
if($result){
header("Location: students.php");
return $result;
}
}
function modifikoStudentet($studentid,$username,$name,$surname,$email,$password){
global $dbcon;
connection();
$sql = "UPDATE students SET name = '$name',surname = '$surname',username = '$username',email='$email',password='$password' WHERE studentid = $studentid";
$result = $dbcon->query($sql);
if($result){
header("Location:dashboard.php");
return $result;
}
}
function shtoInstruktoret($name,$surname,$email,$fieldofstudy,$degree,$country,$password){
global $dbcon;
connection();
$sql = "INSERT INTO instructors(name,surname,email,fieldofstudy,degree,country,password)";
$sql += "VALUES('$name','$surname','$email','$fieldofstudy','$degree','$country','$password')";
$result = $dbcon->query($sql);
if($result){
header("Location: instructors.php");
return $result;
}
}
/*function modifikoInstruktoret($instructorid,$name,$surname,$email,$fieldofstudy,$degree,$country,$password){
global $dbcon;
connection();
$sql = "UPDATE instructors SET name = '$name',surname = '$surname', email = '$email', fieldofstudy = '$fieldofstudy',degree = '$degree',country = '$country',password = '$password' WHERE instructorid = $instructorid";
$result = $dbcon->query($sql);
if($result){
header("Location: instructors.php");
return $result;
}
}*/
function becomeAnInstructor($name,$surname,$email,$password,$fieldofstudy,$degree,$country){
global $dbcon;
connection();
$sql = "INSERT INTO instructors(name,surname,email,password,degree,fieldofstudy,country) VALUES('$name','$surname','$email','$password','$degree','$fieldofstudy','$country')";
$result = $dbcon->query($sql);
header("Location:login.php");
return $result;
}
function kontakto($firstname,$lastname,$country,$subject){
global $dbcon;
connection();
$sql = "INSERT INTO contact(firstname,lastname,country,subject) VALUES('$firstname','$lastname','$country','$subject')";
$result = $dbcon->query($sql);
header("Location:login.php");
return $result;
}
function choseCourse($course,$studentid){
connection();
$sql = "UPDATE students SET course = '".$course."' WHERE studentid = ".$studentid;
$result = $GLOBALS['dbcon']->query($sql);
header("Location:about.php");
return $result;
}