PHP无法发布运行XAMPP的错误 [英] PHP Cannot POST error running XAMPP

查看:26
本文介绍了PHP无法发布运行XAMPP的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在同一目录中使用以下文件时,我在运行 XAMPP 1.8.3 和 [PHP: 5.5.15.

Using the following files in the same directory I have been getting a cannot POST error while running XAMPP 1.8.3 and [PHP: 5.5.15.

<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 文件

Here is my PHP file

<?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.";
}

?>

推荐答案

这是我今天在一些代码中使用的一种技术,它回答了我的问题.

Here is a technique that I used in some code today that answered my question.

<!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 中,以便>"使我能够将表单数据与 IF ('POST' === $_SERVER['REQUEST_METHOD']) 允许我排除 PHP,直到我点击提交按钮.

The pieces that I was missing were located in my initial HTML for action to ""> enabled me to post the form data back to the PHP file combined with the IF ('POST' === $_SERVER['REQUEST_METHOD']) allowed me to exclude the PHP until I clicked on the submit button.

这可能不是执行此操作的正确方法,但由于我使用的是 XAMPP,因此它可以工作.但是我确实知道,如果使用单独的 PHP 和 HTML 文件使用传统的 Web 服务器效果很好.到目前为止,我还没有在我的托管公司完全设置开发环境.暂时必须这样做.

This may not be the proper way to do this but since I am using XAMPP it works. However I do know that if one is using the traditional web server using seperate PHP and HTML files works well. As of yet I have not completely set up the development environment at my hosting company. For the time being this will have to do.

这篇关于PHP无法发布运行XAMPP的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆