在同一目录中使用以下文件我在运行XAMPP 1.8.3和[PHP:5.5.15。
时遇到了一个无法POST错误<html>
<head>
<title> IsEven </title>
</head>
<body>
<form action= "IsEven.php" method="post">
Enter a number: <input type="text" name="number" />
<input type="submit" value="submit" />
</form>
</body>
</html>
这是我的PHP文件
<?php
//Assign Values to the variable.
$number = $_POST['number'];
//If statements to check Even number or not.
//Is_numeric, Isset() and round() functions.
if (is_numeric($number) && isset($number)){
if (round($number, 0) % 2 == 0){
echo "The number " .$number. " entered is a even number<br>";
}
else
{
echo "The number " . $number. " is a non-even number";
} //End round if statement.
} //End is numeric if statement
else
{
echo "Please enter a numeric value.";
}
?>
答案 0 :(得分:0)
这是我今天在一些代码中使用的技术,它回答了我的问题。
<!DOCTYPE HTML>
<html>
<head>
<title> Temperature Conversion </title>
</head>
<body>
<form method="post" action= "<?php echo $_SERVER["PHP_SELF"]; ?>">
Fahrenheit: <input type="radio" name="temp_metric" value="Fahrenheit" />
Celcius: <input type="radio" name="temp_metric" value="Celcius" />
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
<?php
//VARIABLE DECLARATIONS
$degrees = NULL;
$temp_degrees = NULL;
$curr_metric = NULL;
$converted_metric = NULL;
$converted_temp = NULL;
//LOGIC
if ('POST' === $_SERVER['REQUEST_METHOD'] and isset($_POST['temp_metric'])) {
$curr_metric = $_POST['temp_metric'];
for ($degrees = 0; $degrees <= 100; $degrees++) {
if($curr_metric == "Fahrenheit") {
$converted_metric = "Celcius";
$temp_degrees = ($degrees - 32) * (5/9);
$converted_temp = round( $temp_degrees, 1);
}
else {
$curr_metric = "Celcius";
$converted_metric = "Fahrenheit";
$temp_degrees = $degrees * 9/5 + 32;
$converted_temp = round($temp_degrees , 1);
}
//output the result of the users selection
echo "<div> $degrees $curr_metric is $converted_temp $converted_metric. </div>";
}//end of for loop
}//end of if current metric is not null
?>
我遗失的部分位于我最初的HTML中,以便“”&gt;使我能够将表单数据发送回与IF结合的PHP文件('POST'=== $ _SERVER ['REQUEST_METHOD'])允许我排除PHP,直到我点击提交按钮。
这可能不是正确的方法,但因为我使用XAMPP它的工作原理。但是我知道如果使用传统的Web服务器使用单独的PHP和HTML文件效果很好。到目前为止,我还没有在托管公司完全建立开发环境。暂时不得不这样做。