我无法在PHP中同时使用GET和POST [英] I can't use GET and POST at the same time in PHP

查看:118
本文介绍了我无法在PHP中同时使用GET和POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在页面顶部附近,我有这个:

Near the top of my page, I have this:

<?php $id = $_GET['id']; ?>

然后我有一些从POST读取的表单检查条件:

Then I have some form check conditionals that read from POST:

if (isset($_POST['completeSubmit'])) {
        //code
}

最后,我有一个HTML表单,如下所示:

And finally, I have an HTML form which looks like this:

<form action="<?php echo $_SERVER['PHP_SELF']."?id=$id"; ?>" name="complete" method="post">
<input type="submit" id="textButton" name="completeSubmit" value="[mark as complete]">
</form> 

最初使用带有ID变量的GET来访问该页面,如下所示:

The page is initially accessed by using GET with an id variable like this:

http://website.com/page.php?id=1

所有后续表单提交(重定向到同一页面)均失败.我知道您不能在同一请求中同时发送GET和POST,但是看到我的表单正在使用POST提交到$_SERVER['PHP_SELF']."?id=$id",这行不通吗?这是我第一次尝试,所以很可能我忽略了一些琐碎的事情.

All subsequent form submissions (which get redirected to the same page) fail. I know you can't send both GET and POST in the same request, but seeing as my form is submitting to $_SERVER['PHP_SELF']."?id=$id" using POST shouldn't it work? This is my first time trying this so it is quite possible I've overlooked something trivial.

推荐答案

可以同时使用get和post,但您不可以.如果您想继续发送ID,就很简单:

You can use get and post at the same time, but you shouldn't. If you want to continue to send the ID this is as simple as:

<form ...
   <input type="submit" ...
   <input type="hidden" name="id"
      value="<?php echo htmlspecialchars($_GET['id'], ENT_QUOTES); ?>" />
</form>

这篇关于我无法在PHP中同时使用GET和POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆