-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFriendsToDatabase.php
40 lines (35 loc) · 1.46 KB
/
FriendsToDatabase.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
<?php
function DoesFriendExist($Username, $friendname, $birthday, $email, $conn)
{
$sql = $conn->prepare("SELECT * FROM friends WHERE username = ? AND full_name = ? AND date = ? AND email = ?");
$sql->execute([$Username, $friendname, $birthday, $email]);
//confirm that a username in the DB matches the entered one
if ($sql->fetch() != False) {
//if there is a match, return TRUE
return True;
}
//else FALSE because no user of that name exists
else {
return False;
}
}
function StoreFriend($username, $friendname, $birthday, $email, $conn) {
if (!DoesFriendExist($username, $friendname, $birthday, $email, $conn)) {
$request = $conn->prepare("INSERT INTO friends (username, full_name, date, email) VALUES (?,?,?,?)");
$request->execute([$username, $friendname, $birthday, $email]);
}
}
function RemoveFriend($username, $friendname, $birthday, $email, $conn) {
$request = $conn->prepare("DELETE FROM friends WHERE username = ? AND full_name = ? AND date = ? AND email = ?");
$request->execute([$username, $friendname, $birthday, $email]);
}
function RetrieveFriends($username, $conn){
$query = $conn->prepare("SELECT username, full_name, date, email FROM friends WHERE username = ?");
$query->execute([$username]);
$endarray = [];
foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $task){
$endarray[] = $task;
}
return $endarray;
}
?>