-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
111 lines (75 loc) · 2.77 KB
/
functions.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
<?php
require_once("../config_global.php");
require_once("User_class.php");
$database = "if15_helepuh_3";
session_start();
$mysqli = new mysqli($servername, $server_username, $server_password, $database);
//saadan ühenduse classi ja loon uue classi
$User = new User($mysqli);
//var_dump($User->connection);
/*
// Loon AB'i ühenduse
require_once("../config_global.php");
$database = "if15_romil_3";
//tekitatakse sessioon, mida hoitakse serveris,
// kõik session muutujad on kättesaadavad kuni viimase brauseriakna sulgemiseni
session_start();
// võtab andmed ja sisestab ab'i
// võtame vastu 2 muutujat
function createUser($create_email, $hash){
// Global muutujad, et kätte saada config failist andmed
$mysqli = new mysqli($GLOBALS["servername"], $GLOBALS["server_username"], $GLOBALS["server_password"], $GLOBALS["database"]);
$stmt = $mysqli->prepare("INSERT INTO user_sample (email, password) VALUES (?,?)");
$stmt->bind_param("ss", $create_email, $hash);
$stmt->execute();
$stmt->close();
$mysqli->close();
}
function loginUser($email, $hash){
$mysqli = new mysqli($GLOBALS["servername"], $GLOBALS["server_username"], $GLOBALS["server_password"], $GLOBALS["database"]);
$stmt = $mysqli->prepare("SELECT id, email FROM user_sample WHERE email=? AND password=?");
$stmt->bind_param("ss", $email, $hash);
$stmt->bind_result($id_from_db, $email_from_db);
$stmt->execute();
if($stmt->fetch()){
// ab'i oli midagi
echo "Email ja parool õiged, kasutaja id=".$id_from_db;
// tekitan sessiooni muutujad
$_SESSION["logged_in_user_id"] = $id_from_db;
$_SESSION["logged_in_user_email"] = $email_from_db;
//suunan data.php lehele
header("Location: data.php");
}else{
// ei leidnud
echo "Wrong credentials!";
}
$stmt->close();
$mysqli->close();
}
// fn sample
function hello($name, $age){
echo $name." ".$age;
}
//hello("Romil", 5);
// kuigi muuutujad on erinevad jõuab väärtus kohale
function addCarPlate($car_plate, $car_color) {
$mysqli = new mysqli($GLOBALS["servername"], $GLOBALS["server_username"], $GLOBALS["server_password"], $GLOBALS["database"]);
$stmt = $mysqli->prepare("INSERT INTO car_plates (user_id, number_plate, color) VALUES (?,?,?)");
$stmt->bind_param("iss", $_SESSION["logged_in_user_id"], $car_plate, $car_color);
//sõnum
$message = "";
if($stmt->execute()){
// kui on tõene,
//siis INSERT õnnestus
$message = "Sai edukalt lisatud";
}else{
// kui on väärtus FALSE
// siis kuvame errori
echo $stmt->error;
}
return $message;
$stmt->close();
$mysqli->close();
}
*/
?>