Reputation: 171
With the code below I printed out a friendshiprequest on someone's page, for example: friendrequests.php?user_id=4.
The problem: When I click on the 'accept' button I have to stay on that page, but the 'user_id=4' dissapears.
In the action tags of the form I typed $_SERVER['PHP_SELF'] and I also typed the url manually (to test), but that also didn't work.
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_applicant_name']. "</a> has send you a friend request" . "<form action='' type='post'><button type='submit' name=''>Accept</button><button type='submit' name='' >Decline</button></form></p></div>";
}
?>
Upvotes: 1
Views: 58
Reputation: 1474
You are trying to use POST but want to preserve GET parameters at the same time. This can't be done automatically when action=""
.
This answer should work for you: https://stackoverflow.com/a/2749442/2948573
Here's a better formatted working example, using the "REQUEST_URI" variable:
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_applicant_name'] . "
</a> has send you a friend request" . "
<form action='" . $_SERVER["REQUEST_URI"] . "' method='post'>
<button type='submit' name=''>Accept</button>
<button type='submit' name=''>Decline</button>
</form>
</p></div>";
}
Upvotes: 1