-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClients.php
108 lines (92 loc) · 3.29 KB
/
Clients.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
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style_clt.css">
</head>
<body>
<?php
require_once 'Database.php';
class Clients extends SETRAM_Database {
public $ClientID, $FirstName, $LastName, $Dob, $Gender, $PhoneNumber, $Email, $Password, $ProfilePictureID;
public function __construct($ClientID, $FirstName, $LastName, $Dob, $Gender, $PhoneNumber, $Email, $Password, $ProfilePictureID) {
parent::__construct("");
$this->ClientID = $ClientID;
$this->FirstName = $FirstName;
$this->LastName = $LastName;
$this->Dob = $Dob;
$this->Gender = $Gender;
$this->PhoneNumber = $PhoneNumber;
$this->Email = $Email;
$this->Password = $Password;
$this->ProfilePictureID = $ProfilePictureID;
}
public function Clients_Table_Creation($c) {
$Request = "CREATE TABLE IF NOT EXISTS Clients (
ClientID int(5) primary key,
FirstName varchar(40),
LastName varchar(40),
Dob date,
Gender varchar(5),
PhoneNumber int(10),
Email varchar(50),
Password varchar(50),
ProfilePictureID int(10)
)";
$x = $c->prepare($Request);
$e = $x->execute();
if (!$e) {
// echo "Clients table creation error: " . print_r($x->errorInfo(), true) . " <br>";
} else {
// echo "<p class='formtxt'>Clients table created successfully</p>";
}
}
public function Create_New_Client($c) {
$Request = "INSERT INTO Clients (ClientID, FirstName, LastName, Dob, Gender, PhoneNumber, Email, Password, ProfilePictureID)
VALUES (:ClientID, :FirstName, :LastName, :Dob, :Gender, :PhoneNumber, :Email, :Password, :ProfilePictureID)";
$x = $c->prepare($Request);
$e = $x->execute([
':ClientID' => $this->ClientID,
':FirstName' => $this->FirstName,
':LastName' => $this->LastName,
':Dob' => $this->Dob,
':Gender' => $this->Gender,
':PhoneNumber' => $this->PhoneNumber,
':Email' => $this->Email,
':Password' => $this->Password,
':ProfilePictureID' => $this->ProfilePictureID
]);
if (!$e) {
echo "Client account creation error: " . print_r($x->errorInfo(), true) . " <br>";
} else {
echo "<p class='formtxt'>Client $this->FirstName $this->LastName has been Created successfully</p>";
}
}
public function View_Clients($c){
try {
$request = "SELECT * FROM Clients LEFT JOIN images ON images.id = Clients.ProfilePictureID";
$stmt = $c->prepare($request);
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
return [];
}
}
public function Delete_Client($c, $ClientID)
{
try {
$request = "DELETE FROM Clients WHERE ClientID = :ClientID";
$stmt = $c->prepare($request);
$stmt->bindParam(':ClientID', $ClientID, PDO::PARAM_INT);
$stmt->execute();
return true;
echo "Client $ClientID deleted";
} catch (PDOException $e) {
return false;
}
}
}
?>
</body>
</html>