forked from psai11/Social-Networking-File
-
Notifications
You must be signed in to change notification settings - Fork 0
/
requests.php
54 lines (37 loc) · 1.66 KB
/
requests.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
<?php
require_once("includes/header.php");
?>
<div class="main_column column" id="main_column">
<h4>Friend requests</h4>
<?php
$query = mysqli_query($con, "SELECT * FROM FRIEND_REQUESTS WHERE USER_TO='$userLoggedIn'");
if(mysqli_num_rows($query) == 0)
echo "You have no friend requests at this time!";
else {
while ($row = mysqli_fetch_array($query)) {
$user_from = $row['USER_FROM'];
$user_from_obj = new User($con, $user_from);
echo $user_from_obj->getName(). " sent you a friend request!";
$user_from_friend_array = $user_from_obj->getFriendArray();
if (isset($_POST['accept_request'. $user_from])) {
$add_friend_query = mysqli_query($con, "UPDATE USER SET FRIEND_ARRAY=CONCAT(FRIEND_ARRAY, '$user_from,') WHERE USERNAME='$userLoggedIn'");
$add_friend_query = mysqli_query($con, "UPDATE USER SET FRIEND_ARRAY=CONCAT(FRIEND_ARRAY, '$userLoggedIn,') WHERE USERNAME='$user_from'");
$delete_query = mysqli_query($con, "DELETE FROM FRIEND_REQUESTS WHERE USER_TO='$userLoggedIn' AND USER_FROM='$user_from'");
echo "You are now friends!";
header("Location: requests.php");
}
if (isset($_POST['ignore_request'. $user_from])) {
$delete_query = mysqli_query($con, "DELETE FROM FRIEND_REQUESTS WHERE USER_TO='$userLoggedIn' AND USER_FROM='$user_from'");
echo "Request ignored!";
header("Location: requests.php");
}
?>
<form action="requests.php" method="POST">
<input type="submit" name="accept_request<?php echo $user_from; ?>" id="accept_button" value="Accept">
<input type="submit" name="ignore_request<?php echo $user_from; ?>" id="ignore_button" value="Ignore">
</form>
<?php
}
}
?>
</div>