-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkFriend.php
49 lines (35 loc) · 1.35 KB
/
checkFriend.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
<?php
session_start();
//$db = mysqli_connect('localhost', 'root', 'password', 'test');
define("DB_HOST", "localhost");
define("DB_USER", "root");
define("DB_PASSWORD", "");
define("DB_DATABASE", "test");
//Create new database named test
$db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
$testdatabase = mysql_select_db("test");
if($db->connect_error){
print "Error - Could not connnect to MySQL";
exit;
}
$checking = $_POST["name"];
$designatedName = $_SESSION['Username'];
$selectDD = mysqli_query($db,"SELECT * FROM Users WHERE Username = '$designatedName'");
$userInfo = mysqli_fetch_array($selectDD);
$userID = $userInfo['ID'];
$f1 = mysqli_query($db,"SELECT * FROM Relationship WHERE Friend1 = $userID");
$f2 = mysqli_query($db,"SELECT * FROM Relationship WHERE Friend2 = $userID ");
//fetch every person that is friends with the designated driver, check as if they were friend 1 first and then friend 2
while($row = mysqli_fetch_array($f1)){
//if this person exists and they are friends (status = 2) then append it to the page
if($row['Friend2'] == $checking && $row['Status'] == 2){
echo $checking;
}
}
while($rowS = mysqli_fetch_array($f2)){
//if this person exists and they are friends (status = 2) then append it to the page
if($rowS['Friend1'] == $checking && $rowS['Status'] == 2){
echo $checking;
}
}
?>