GetAllFriendRequests function
The structure of the array you're returning is the problem. Instead of
while ($row = mysqli_fetch_array($result)) {
$result_array[]=$row;
}
Do:
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$result_array[]=$row;
}
Also, FYI, you don't need this line in the GetAllFriendRequests function:
$result_array=array();
Because the brackets in this line (inside the while loop) make it an array automatically:
$result_array[]=$row;
Main PHP file
Your form in your main PHP file needs to change as well. This prints out all the relevant data, but I've changed a few things - both submit buttons now have a name, so they will appear in the POST array. Also, there is a hidden input with the friendship_id you'll need to run your AcceptFriendRequest function. If they click Accept, then (1) the data is POSTed back to the same file and the pages refreshes, (2) the if(isset) condition checks to see if they have accepted the request. (3) It calls the AcceptFriendRequest function using the friendship_id we stored in the hidden input. Each form on the page will have a hidden input like this. You may need other hidden inputs if you need more variables from the specific request - for instance if you need other data to run the Decline function.
<?php
foreach ($friendrequests as $request) {
echo "
<div><p>
<a href='profile.php?user_id=".$request['friendship_applicant_id'] . "'>
<img src='uploads/" . $request['friendship_applicant_avatar'] . " " . " ' alt='' />" . $request['friendship_applicant_surname'] . $request['friendship_id'] . " " . $request['friendship_applicant_name'] . "
</a> has send you a friend request" . "
<form action='" . $_SERVER['REQUEST_URI'] . "' method='post'>
<button type='submit' name='Accept'>Accept</button>
<button type='submit' name='Decline'>Decline</button>
<input type='hidden' name='acceptID' value='".$request['friendship_id']."' />
</form>
</p></div>";
}//foreach
if (isset($_POST['Accept'])){
$accepted = AcceptFriendRequest($_POST['acceptid']);
//for debugging, you may want to uncomment this and watch what your function returns
//echo $accepted;
}
if (isset($_POST['Decline'])){
//some other function is the request is declined
}
?>