Php 行动可以';t加载正确的页面(url)
使用下面的代码,我在某人的页面上打印了一个friendrequests,例如:friendrequests.php?user_id=4 问题是:当我点击“接受”按钮时,我必须停留在该页面上,但是“用户id=4”消失了 在表单的action标记中,我键入了$_SERVER['PHP_SELF',我还手动键入了url(以进行测试),但这也不起作用Php 行动可以';t加载正确的页面(url),php,forms,redirect,action,Php,Forms,Redirect,Action,使用下面的代码,我在某人的页面上打印了一个friendrequests,例如:friendrequests.php?user_id=4 问题是:当我点击“接受”按钮时,我必须停留在该页面上,但是“用户id=4”消失了 在表单的action标记中,我键入了$_SERVER['PHP_SELF',我还手动键入了url(以进行测试),但这也不起作用 foreach ($friendrequests as $request) { echo "<di
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>";
}
?>
foreach($friendrequests作为$request){
echo“已向您发送好友请求”,“接受拒绝”;
}
?>
您试图使用POST,但同时希望保留GET参数。当action=”“
时,无法自动执行此操作
这个答案应该适合你:
下面是一个格式更好的工作示例,使用“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>";
}
foreach($friendrequests作为$request){
回声“
已向您发送好友请求“
接受
减少
”;
}
当我用方法替换type by并手动键入url时,它正在工作,但当我在action标记中键入$\u SERVER['PHP\u SELF']时,它总是给出一个语法错误。。。提前谢谢!方法而不是类型:)是的,我忽略了这一点嗯,它起作用了。非常感谢。PHP_服务器SELF中的REQUEST_URI有什么区别?您可以在这里找到:REQUEST_URI基本上返回给定的整个URI,PHP_SELF只是文件的路径(不包括?部分)