【问题标题】:how to submit a form to itself by using post method in php? [duplicate]如何使用 php 中的 post 方法向自己提交表单? [复制]
【发布时间】:2017-01-12 11:49:20
【问题描述】:

我正在尝试通过 post 方法自行提交表单。但每次提交表单并刷新页面时。它不显示值。

<?php echo $_POST['fname']; ?>
<form method="POST" action='#.php'>
<input type="text" name="fname" id="fname" />
<button id="check" name="check" type="submit">GO</button>
</form>

什么意思,我不见了?

【问题讨论】:

  • 保持操作空白 action=""
  • 假设您的文件名不是#.php

标签: php post


【解决方案1】:

试试这个:

<?php echo $_POST['fname']; ?>
<form method="POST" action=""> <!-- not single quote -->
<input type="text" name="fname" id="fname" />
<input type="submit" name="value" >
</form>

【讨论】:

  • 试过了,没用
  • action = "" 不是单引号
  • @AmanBarnwal,我得到了我在文本框中输入的任何内容。你能给我你的完整代码吗?您在哪个浏览器上执行脚本?
  • 这是我桌面上的示例页面
  • @Aman Barnwal 将 action='#.php' 替换为 action = ""
【解决方案2】:

试试这个……

<?php 

如果 ($_SERVER['REQUEST_METHOD'] == 'POST') {

echo "<pre>";
print_r($_POST);

} ?>

<form name="test" action="" method="post"><input type="text" name="firstName" /><input type="submit" name="Submit" /></form>

【讨论】:

    【解决方案3】:

    我会建议写更干净的方式。像这样:

    <?php 
    if(isset($_POST['fname']) && !empty($_POST['fname']) ){
     echo $_POST['fname'];
    }
    ?>
    <form method="POST" action=""> <!-- not single quote -->
    <input type="text" name="fname" id="fname" />
    <input type="submit" name="value" >
    </form>
    

    【讨论】:

      猜你喜欢
      • 2011-08-15
      • 1970-01-01
      • 2014-01-21
      • 2014-11-10
      • 1970-01-01
      • 2011-01-19
      • 1970-01-01
      • 1970-01-01
      • 2012-09-15
      相关资源
      最近更新 更多