-
Notifications
You must be signed in to change notification settings - Fork 0
/
requests.php
54 lines (37 loc) · 1.67 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
include("includes/header.php"); //Header
?>
<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->getFirstAndLastName() . " 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 users SET friend_array=CONCAT(friend_array, '$user_from,') WHERE username='$userLoggedIn'");
$add_friend_query = mysqli_query($con, "UPDATE users 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>