0
我創建了一個簡單的php
頁面,需要驗證輸入的金額是greater than 100
還是必須返回error
。我的功能雖然發佈時不會被調用且金額less than 100
函數未驗證
<html>
<head></head>
<title></title>
<style>
.error {color: #FF0000;}
</style>
<body>
<?php
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$amountErr = "";
$amount = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (($_POST["amount"]) > 100) {
$amountErr = "Value must be equal or greater than 100";
} else {
$amount = test_input($_POST["amount"]);
}
}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<p><span class="error">*required field.</span></p>
Amount:<input type="text" name="amount"/>
<span class="error">*<?php echo $amountErr; ?></span>
<input type="submit" value="Pay"/>
</form>
</body>
</html>
@Karl有人想要點。當你幫助這些匿名用戶時感到羞愧,他們只是回答並離開,永遠不會再被看到,直到他們的下一期。 –