PHP $ _POST不工作? [英] PHP $_POST not working?

查看:134
本文介绍了PHP $ _POST不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有最简单的形式,我想要做的就是回应文本框中写的任何内容。


$ b HTML:

 < form action =method =post> 
< input type =textname =firstname>
< input type =submitname =submitvalue =Submit>
< / form>

PHP:

  if(isset($ _ POST ['submit'])){
$ test = $ _POST ['firstname'];
echo $ test;



$ b $ p
$ b

问题是它不能在我的服务器上工作(它在另一台服务器上工作) 。有没有人有一个想法可能是错的?在服务器上还有其他的表单,并且工作正常。

解决方案

您可以执行一些操作:


  1. 请确保表单上的action属性导致正确的目的地。
  2. 尝试使用$ _REQUEST []而不是$ _POST,看看是否有任何改变。

  3. [可选]尝试包括'name'和'id'属性,例如

     < input type =textname =firstnameid =firstname> 


  4. 在Linux环境中,请检查您是否拥有对该文件的读/写权限。

  5. link 也可能有帮助。

    编辑:

    如果(isset($ _ POST ['submit'])){您也可以替换
    >
    with this:
    if($ _ SERVER ['REQUEST_METHOD'] ==POST){。这总是检查表单是否已被提交的最佳方式。

    I have the simplest form possible and all I want to do is echo whatever is written in text box.

    HTML:

    <form action="" method="post">
      <input type="text" name="firstname">
      <input type="submit" name="submit" value="Submit">
    </form>
    

    PHP:

    if(isset($_POST['submit'])){
      $test = $_POST['firstname'];
      echo $test;
    }
    

    The problem is it's not working on my server (it works on another server). Does anyone has an idea what could be wrong? There are other forms on the server and are working fine.

    解决方案

    A few thing you could do:

    1. Make sure that the "action" attribute on your form leads to the correct destination.
    2. Try using $_REQUEST[] instead of $_POST, see if there is any change.
    3. [Optional] Try including both a 'name' and an 'id' attribute e.g.

      <input type="text" name="firstname" id="firstname">
      

    4. If you are in a Linux environment, check that you have both Read/Write permissions to the file.

    In addition, this link might also help.

    EDIT:

    You could also substitute if(isset($_POST['submit'])){ with this: if($_SERVER['REQUEST_METHOD'] == "POST"){ . This is always the best way of checking whether or not a form has been submitted

    这篇关于PHP $ _POST不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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