使用下面的代码,我在某人的页面上打印出一个友情请求,例如:friendrequests.php?user_id = 4.
问题:当我点击“接受”按钮时,我必须留在该页面上,但'user_id = 4'消失了。
在我输入$ _SERVER ['PHP_SELF']的表格的动作标签中,我也手动输入了网址(进行测试),但这也没有用。
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>";
}
?>
答案 0 :(得分:1)
您正在尝试使用POST,但希望同时保留GET参数。 action=""
。
这个答案对你有用: https://stackoverflow.com/a/2749442/2948573
这是一个更好的格式化工作示例,使用“REQUEST_URI”变量:
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>";
}