php - 我会在一页中使用 $ _POST 两次
问题描述
我有一个付款的网站,通过它创建账单,但问题是我不能一次使用 $ _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>
<? } ?>
解决方案
试试这个。
请检查代码以获取评论。
<?
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>
}
?>
推荐阅读
- node.js - Lambda S3 getObject - 拒绝访问 - 无服务器框架
- c# - 需要帮助来理解这部分代码是如何工作的
- unity3d - Holographic Remoting (Hololens 2) connection problem in both Unity and Unreal : TransportConnectionFailed
- sql - 嵌套 IF 存储过程中的局部变量
- java - Android google drive v3 api 文件不是创建/存储特定于应用程序的文件夹,而是它在我的驱动器部分中使用“Untitile”文件名创建
- teamcity - 如果我在 TeamCity 构建中“启动”一个进程,它会在构建完成时被删除吗?
- bootstrap-4 - 如何设置 Bootstrap,以便我的 Vue 应用程序可以使用正确的版本,具体取决于语言设置?
- java - 在java中使用命令行运行python
- php - 是否可以结合mysql和mongodb数据库进行排序
- javascript - 滑块过渡有误