Php 我会在一个页面中使用$\u POST两次

Php 我会在一个页面中使用$\u POST两次,php,Php,我有一个网站,我在那里付款,通过它创建账单,但问题是我不能在一个网站中使用$\u POST两次,下面的示例: <? if (isset($_POST['submit'])) { ?> <form action="" method="POST" > <input name="invoice" value="" type="text" /> <input name="pay"

我有一个网站,我在那里付款,通过它创建账单,但问题是我不能在一个网站中使用$\u POST两次,下面的示例:

    <?  if (isset($_POST['submit'])) { ?>
        <form action="" method="POST" >
              <input name="invoice" value="" type="text" />
              <input name="pay" value="Pay Now" type="submit" />
        </form>
<? }   if (isset($_POST['pay'])) {
        // MY QUERY HERE
        // HEADERS HERE
} else { ?>
<form action="" method="POST" >
    <input name="info" value="" type="text" />
    <input name="submit" value="Submit" type="submit" />
</form>  
<?  } ?>

这不是最漂亮的方法,但要达到你的效果,试试这个

<?php if (isset($_POST['submit'])) { ?>
    <form action="" method="POST" >
        <input name="invoice" value="" type="text" />
        <input name="pay" value="Pay Now" type="submit" />
    </form>
<?php } elseif (isset($_POST['pay'])) { 

    // Perform query here

} else { ?>
    <form action="" method="POST" >
        <input name="info" value="" type="text" />
        <input name="submit" value="Submit" type="submit" />
    </form>
<?php } ?>
试试这个

请检查代码以获取评论

<?
  if (isset($_POST['submit'])) {
    $info = $_POST['info'];
   // use echo to display second form
   echo '
    <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST" >
      <!-- // Note the action value, it's for post back. This allow you to post back to the current page -->
      <!-- This is to keep the record passed from the first form -->
      <input name="info" value="'. $info .'" type="hidden" />
      <input name="invoice" value="" type="text" />
      <input name="pay" value="Pay Now" type="submit" />
    </form>';
  } else if (isset($_POST['pay'])) {

    // MY QUERY HERE

  } else {
    // Note the action value, it's for post back. This allow you to post back to the current page
    <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST" >
       <input name="info" value="" type="text" />
       <input name="submit" value="Submit" type="submit" />
    </form>
  }
?>

看看你的PHP错误日志,这只需要生成编译错误,或者在打开PHP标签后测试时在文件顶部添加一些错误,例如,为什么匿名否决投票?解释你自己。这就解决了OP的问题,不是吗?