-
Notifications
You must be signed in to change notification settings - Fork 0
/
InterestsManager.class.php
74 lines (47 loc) · 1.54 KB
/
InterestsManager.class.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
<?php
class InterestsManager{
//InterestsManager.class.php
private $connection;
private $user_id;
//kui tekitan new siis käivitatakse see funktsioon
function __construct($mysqli, $user_id_from_session){
// selle klassi muutuja
$this->connection = $mysqli;
$this->user_id = $user_id_from_session;
echo "Huvialade haldus käivitatud, kasutaja=".$this->user_id;
}
function addInterest(){
$response = new StdClass();
//kas selline email on juba olemas
$stmt = $this->connection->prepare("SELECT id FROM interests Where name=?");
$stmt->bind_param("s", $new_interest);
$stmt->bind_result($id);
$stmt->execute();
//kas sain rea andmeid
if($stmt->fetch()){
//annan errori, et selline email on olemas
$error = new StdClass();
$error->id = 0;
$error->message = "Huviala <strong>".$new_interest."</strong> on juba olemas!";
$response->error = $error;
return $response;
}
//panen eelmise päringu kinni
$stmt->close;
$stmt = $this->connection->prepare("INSERT INTO interests (name) VALUES (?)");
$stmt->bind_param("s", $new_interest);
//sai edukalt salvestatud
if($stmt->execute()){
$success = new StdClass();
$success->message = "Huviala edukalt lisatud!";
$response->success = $success;
}else{
//midagi läks katki
$error = new StdClass();
$error->id = 1;
$error->message = "Midagi läks katki!";
$response->error = $error;
}
}
}
?>