2015-02-02 2 views
1

Использование следующих файлов в том же каталоге, что я получаю сообщение об ошибке POST при запуске XAMPP 1.8.3 и [PHP: 5.5.15.PHP Не удается выполнить POST-ошибку XAMPP

<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

Где вы узнали об ошибке? в консоли javascript? Можете ли вы показать нам ошибку? – satchcoder

+0

$ number = $ _POST ['number']; PLS редактировать в $ number = isset ($ _ POST ['number'])? $ _ POST ['number']: null; – donald123

+0

веб-браузер отображает «Can not POST /ITSE2302/IsEven.php» адрес http://127.0.0.1:53932/ITSE2302/IsEven.php –

ответ

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 для действия в «»> дало мне возможность отправлять данные формы обратно в файл PHP в сочетании с IF («POST» === $ _SERVER ['REQUEST_METHOD']) позволил мне исключить PHP, пока я не нажал кнопку отправки.

Это может быть неправильный способ сделать это, но поскольку я использую XAMPP, он работает. Однако я знаю, что, если вы используете традиционный веб-сервер, используя отдельные PHP и HTML-файлы, хорошо работает. На данный момент я еще не полностью настроил среду разработки на своей хостинговой компании. Пока это нужно будет сделать.

Смежные вопросы