【发布时间】:2021-08-23 03:35:40
【问题描述】:
我想用这个 PHP 代码更新发票上的价格(包含配置文件,在此之上执行更多 SQL 语句):
<?php
$finalprice = getInvoicePrice($code);
$codeErr = "";
$discount = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["discount"])) {
$codeErr = "Code can not be blank.";
}else {
$discount = test_input($_POST["discount"]);
if ($discount == "FIVE" ) {
$codeErr = "OK";
$price = getInvoicePrice($code);
$percentage = 100;
$percentage = 100 - 5;
$finalprice = $percentage / 100 * $price;
$SQLChangePrice = $odb->prepare("UPDATE `invoices2` SET `price` = :price WHERE `code` = `:code`");
$SQLChangePrice->execute(array(
":price" => $finalprice,
":code" => $code
));
}else {
$codeErr = "wrong code";
$price = getInvoicePrice($code);
$finalprice = $price;
}
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
完整代码(html表单):
<form method = "post" onsubmit="return submitDiscount();">
<table>
<tr>
<td>code:</td>
<td><input type = "text" name = "discount">
<span class = "error"><?php echo $codeErr;?></span>
</td>
</tr>
<td>
<input type = "submit" name = "submit" value = "Submit">
</td>
</table>
</form>
整个脚本和周围的东西都在工作,但是 MYSQL exec。由于某些原因无法正常工作(完全没有错误)
【问题讨论】: