用php写一个下拉列表框填写加款扣款
以下是一个简单的例子:
<form method="post">
<label for="transaction_type">交易类型:</label>
<select id="transaction_type" name="transaction_type">
<option value="add">加款</option>
<option value="deduct">扣款</option>
</select><br><br>
<label for="amount">金额:</label>
<input type="text" id="amount" name="amount"><br><br>
<label for="reason">原因:</label>
<input type="text" id="reason" name="reason"><br><br>
<input type="submit" value="提交">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$transaction_type = $_POST["transaction_type"];
$amount = $_POST["amount"];
$reason = $_POST["reason"];
if ($transaction_type == "add") {
// 加款操作
echo "已成功加款 $amount 元,原因是 $reason。";
} else {
// 扣款操作
echo "已成功扣款 $amount 元,原因是 $reason。";
}
}
?>
在上面的例子中,我们使用了一个下拉列表框来选择交易类型,有“加款”和“扣款”两个选项。当用户提交表单时,我们通过 $_POST 获得用户填写的数据,根据交易类型来执行相应的操作。在这个例子中,我们只是简单地输出一条成功操作的信息,实际应用中应该根据具体情况进行处理。
原文地址: https://www.cveoy.top/t/topic/Jje 著作权归作者所有。请勿转载和采集!