我在互联网上搜索过,无法找到问题的解决方案。这是我的问题,我有一个帖子脚本,在数据库中输入用户的帖子和用户ID。我想要做的是从我的网站上的不同页面发布后,重定向回到用户刚刚访问的页面。所有这些都将在用户登录网站后进行,因此不是重定向到登录页面的方式,而是返回用户在提交帖子后所在的页面。问题是它发送到profile_test2.php,即使我是从homepage.php发布的。
以下是我表格中的代码:
<form name="form" id="form" method="POST" action="add_post.php?bev=1">
<input type="text" name="textbox" id="textbox" spellcheck="true">
<input type="submit" value="submit">
</form>
这是php脚本中的代码:
// Get the page the user posted from
$page = $_GET['bev'];
//Redirect this user to the page that displays user information
if ($_GET['bev'] == '1') {
$url = 'homepage.php';
} else if ($_GET['bev'] == '2') {
$url = 'profile_test2.php';
} else {
$url = 'profile_test2.php';
}
header('Location: '. $url);
exit();
提前谢谢!
答案 0 :(得分:0)
不能有action
个$_GET
个网址的表单。您可以使用<input type='hidden' name='bev' value='1' />
。由于您的方法是$_POST
,我会使用$_POST['bev']
。
答案 1 :(得分:0)
+1用于Pekka关于在表单中使用不可见元素的注释,而不是让GET变量通过POST表单。
<input type="hidden" name="bev" value="1">
如果页面总是重定向到profile_test2.php,那么很可能GET函数不起作用,它总是在php脚本中属于ELSE
条件。您可能希望echo the $url
只是仔细检查一下。