我创建了一个简单的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>