2017-05-01 7 views
0

私はこれがあなたの多くにとって非常に簡単だと確信しています!私は基本的なHTML/PHPフォーム処理を学びたいと考えています。このサイトは、ローカルのApacheサーバーでホストされています。 PHPが正常に動作していて、サーバがうまく動作していることがうれしいです。HTMLフォームを処理する単純なPHP

私は2つのファイルを持っています.1つはsettings.htmlです。ユーザーは3つの要素の形式を持ち、フロート値を入力できます(湿度、温度、光の許容値)。送信ボタンは、process.phpという3つの値を表示する別のファイルをトリガします。コードは以下の通りである:

settings.html:

<!DOCTYPE html> 
<html> 
    <head> 
     <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> 
    <meta http-equiv="refresh" content="179" > 
    <title>Sparks - Settings</title> 
    <link rel="stylesheet" type="text/css" href="css/default.css"> 
    </head> 
    <body> 
    <div id="logo"> 
     <img style="width: 335px; height: 142px;" alt="ESP8266 Logo" src="images\imgESP8266.png"> 
    </div> 
    <br> 
    <form method="post" action="php/process.php"> 
     Humidity Tolerance : <input type="float" name="humTolerance" placeholder="Enter %" /><br /> 
     Temperature Tolerance : <input type="float" name="tempTolerance" placeholder="Enter %" /><br /> 
     Light Tolerance : <input type="float" name="lightTolerance" placeholder="Enter %" /><br /> 
     <input type="submit" value="Submit" /> 
    </form> 
    </body> 
<html> 

PHP/process.php:

<?php //process.php 
    if ($_SERVER["REQUEST_METHOD"] == "POST") { 
     $humTolerance = $_POST["humTolerance"]; 
     $tempTolerance = $_POST["tempTolerance"]; 
     $lightTolerance = $_POST["lightTolerance"]; 
    } 

    echo <<<_END 
    <html> 
     <head> 
     <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> 
     <meta http-equiv="refresh" content="179" > 
     <title>Sparks - Settings</title> 
     <link rel="stylesheet" type="text/css" href="css/default.css"> 
     </head> 
     <body> 
     humTolerance is: $humTolerance<br> 
     tempTolerance is: $tempTolerance<br> 
     lightTolerance is: $lightTolerance<br> 
     </body> 
    </html> 
    _END; 
?> 

これはHTTPエラー500を生産していると私は理由を見ることはできません。助けてもらえますか?ありがとう。

+0

(最初の)問題は、あなたのheredocの終了識別子http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredocにあります。その前にスペースが含まれています。 –

+0

2番目の: 'type =" float "は入力のための有効な型ではありませんhttps://developer.mozilla.org/en/docs/Web/HTML/Element/input --- http:// html5doctor .com/html5-forms-input-types/--- https://www.w3.org/wiki/HTML5_form_additions –

+2

あなたのPHPページでhttp 500を取得した場合、PHPにエラーがあります。表示するようにphp.iniを設定しますエラーメッセージを表示してコードをデバッグするのに役立ちます。 –

答えて

3

私はコメントで言ったように:

「(最初の)問題は、それはそれの前にスペースが含まれているあなたのheredoc closing identifierです。」

「1秒:type="float"は、入力のための有効なタイプではありません」

あなたは有効なもので、それらの入力タイプを交換する必要があります。

ないすべてのブラウザが特定のHTML5属性をサポートしていることを注意、参考として上記を参照してください。

type="number"またはtype="text"を使用してください。

閉じるheredoc識別子の前に空白があるPHP。

<?php //process.php 
    if ($_SERVER["REQUEST_METHOD"] == "POST") { 
     $humTolerance = $_POST["humTolerance"]; 
     $tempTolerance = $_POST["tempTolerance"]; 
     $lightTolerance = $_POST["lightTolerance"]; 
    } 

    echo <<<_END 
    <html> 
     <head> 
     <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> 
     <meta http-equiv="refresh" content="179" > 
     <title>Sparks - Settings</title> 
     <link rel="stylesheet" type="text/css" href="css/default.css"> 
     </head> 
     <body> 
     humTolerance is: $humTolerance<br> 
     tempTolerance is: $tempTolerance<br> 
     lightTolerance is: $lightTolerance<br> 
     </body> 
    </html> 
_END; 
?> 

使用PHPのエラー報告も:

あなたはログへのアクセスを持っていない場合は、キャッチして表示することを設定します。

+1

** [この投稿](http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display)**への私の静かなリンクを繰り返しますが、 +10 ':-D' – Martin

+0

@Martinマーティンありがとう、*歓声* –

関連する問題