gpt4 book ai didi

php - 表单操作和发布方法不起作用 php

转载 作者:行者123 更新时间:2023-11-29 17:24:04 24 4
gpt4 key购买 nike

我有一个 pay.php 脚本,需要在输入金额后执行。但文件 pay.php 未加载。

html代码:

<div class="sap_tabs">
<div id="horizontalTab" style="display: block; width: 100%; margin: 0px;">
<div class="pay-tabs">
<h2>Select Payment Method</h2>
<ul class="resp-tabs-list">
<li class="resp-tab-item" aria-controls="tab_item-0" role="tab"><span><label class="pic1"></label>Cash</span></li>
<li class="resp-tab-item" aria-controls="tab_item-1" role="tab"><span><label class="pic3"></label>Cheque</span></li>
<li class="resp-tab-item" aria-controls="tab_item-2" role="tab"><span><label class="pic4"></label>Mobile Money</span></li>
<div class="clear"></div>
</ul>
</div>
<div class="resp-tabs-container">
<div class="tab-1 resp-tab-content" aria-labelledby="tab_item-0">
<div class="payment-info">
<h3>Details</h3>
<form method ="post" action"pay.php">
<div class="tab-for">
<h5>Amount</h5>
<input type="text" name = "amount" id ="amount" required />
</div>
<input type="submit" value="Submit" />
</form>

</div>
</div>

当我单独加载文件 pay.php 时,我没有遇到任何问题。 但是当我输入金额并单击“提交”时,表单操作不会运行或无法将数据插入数据库。

PHP 代码:

<?php
if(isset($_POST['Submit'])){
$username="xxxx"; // Mysql username
$password="xxxx"; // Mysql password
$db_name="shipping_pro"; // Database name
$tbl_name="payment_cash";

try {

//connection
$conn = new PDO('mysql:host=localhost;dbname=shipping_pro', $username,
$password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$amount = filter_input(INPUT_POST, 'amount');
$sql= "INSERT INTO payment_cash(Amount) VALUES('$amount')";
if ($conn->query($sql)) {
echo "<script type=\"text/javascript\">
alert(\"Payment Received Thank You!.\");
window.location = \"../dashboard/index.php\"
</script>";
}

}
catch (PDOException $e) {
echo $e->getMessage();
}
}
?>

最佳答案

<form method ="post" action"pay.php">

应该是

<form method ="post" action="pay.php">

关于php - 表单操作和发布方法不起作用 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51073196/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com