2016-08-05 8 views
0

OK、私は作成しようとしているウェブサイト用のフォームを持っています。私はHTMLからのユーザー入力をPHPに表示される文字列値に格納しようとしています。問題は、私が想定している数値の型を入力すると、PHPによって認識されないということです。これは、 "ラジオボタン"タイプの入力では機能しますが、プレーンテキストでは機能しません。私はサイトの両方のページにコードを含めました。 タワーデザインセンター - ここに独自のタワーを作りましょう!これらの結果を組み合わせた場合数字が配列に文字列として登録されていません

<?php var_dump($_POST) ?><br> 
    Pillar base shape: <?php echo $_POST["tBase"]; ?><br> 
    Pillar dimensions: <?php echo htmlspecialchars($_POST["tHeight"])." x ".htmlspecialchars($_POST["tWidth"])." x ".htmlspecialchars($_POST["tDepth"]); ?><br> 

はこれまでのところ、私はのためのvar_dump配列内の文字カウントを見ることができます:私はPHPコードで、これまで持って何

<body> 
    <h1 style="font-family:impact; font-size:72; color:silver;">Tower Design Centre</h1> 
    <p style="font-family:courier; font-size:22; color:blue;">Build your own tower here!</p> 
    <p style="font-family:arial; font-size:12; color:black;"> Welcome to Tower Builder! Please select shapes and dimensions for the different parts of your tower.</p> 

    <form action="testfile_post.php" method="post" target="_blank" accept-charset="UTF-8"> 
     Select pillar base shape:<br> 
     <input type="radio" name="tBase" value="Circle" checked>Circle<br> 
     <input type="radio" name="tBase" value="Triangle" checked>Triangle<br> 
     <input type="radio" name="tBase" value="Rectangle" checked>Rectangle<br> 
     <input type="radio" name="tBase" value="Pentagon" checked>Pentagon<br> 
     <input type="radio" name="tBase" value="Hexagon" checked>Hexagon<br> 
     <input type="radio" name="tBase" value="Heptagon" checked>Heptagon<br> 
     <input type="radio" name="tBase" value="Octagon" checked>Octagon<br> 
     <!--Set variable tBase equal to user's option. --> 

     <fieldset> <!-- Use height/width to make fieldset border smaller in order to fit picture of tower being built.--> 
      <legend>Pillar dimensions:</legend> 
      Height:<br> 
      <input type="text" name="tHeight"><br> 
      <!-- User must input height option. Text should only be positive integers greater than zero. Set variable tHeight equal to user's input. Must comply with ratios.--> 
      Width:<br> 
      <input type="text" name="tWidth"><br> 
      <!-- Same constraints as height apply. Set variable tWidth equal to user's input.--> 
      Depth:<br> 
      <input type="text" name="tDepth"><br> 
      <!-- Same constraints as height and width. Set variable tDepth equal to user's input.--> 
      Slant:<br> 
      <input type="text" name="tSlant"><br> 
      <!--Set variable tSlant equal to user input. tSlant cannot exceed -45 or 45. If it does, throw error message and do not allow user to continue. 
     Neg. and pos. integers, as well as zero, may be used. If tSlant >= 35 or <= -35, throw Leaning Tower communication.--> 
     </fieldset> 

     Select pod shape:<br> 
     <input type="radio" name="pShape" value="Circle" checked>Circle<br> 
     <input type="radio" name="pShape" value="Triangle" checked>Triangle<br> 
     <input type="radio" name="pShape" value="Rectangle" checked>Rectangle<br> 
     <input type="radio" name="pShape" value="Pentagon" checked>Pentagon<br> 
     <input type="radio" name="pShape" value="Hexagon" checked>Hexagon<br> 
     <input type="radio" name="pShape" value="Heptagon" checked>Heptagon<br> 
     <input type="radio" name="pShape" value="Octagon" checked>Octagon<br> 
     <!-- Set variable pShape equal to user's option. --> 

     <fieldset> <!-- Use height/width to make fieldset border smaller in order to fit picture of tower being built.--> 
      <legend>Pod dimensions:</legend> 
      Height:<br> 
      <input type="text" name="pHeight"><br> 
      <!--Text should only be positive integers greater than zero. Set variable pHeight equal to user's input.--> 
      Width:<br> 
      <input type="text" name="pWidth"><br> 
      <!-- Same constraints as height apply. Set variable pWidth equal to user's input.--> 
      Depth:<br> 
      <input type="text" name="pDepth"><br> 
      <!-- Same constraints as height and width. Set variable pDepth equal to user's input.--> 
    </fieldset> 

    <fieldset> 
     <legend>Pod placement:</legend> 
     <input type="text" name="pPlace1"><br> 
     <!--Set variable pPlace1 equal to user's input. --> 
     out of<br> 
     <input type="text" name="pPlace2"><br> 
     <!--Set variable pPlace2 equal to user's input.--> 
    </fieldset> 
    <!-- Do not let pPlace1 exceed pPlace2.--> 

    Select spindle base shape:<br> 
    <input type="radio" name="sShape" value="Circle" checked>Circle<br> 
    <input type="radio" name="sShape" value="Triangle" checked>Triangle<br> 
    <input type="radio" name="sShape" value="Rectangle" checked>Rectangle<br> 
    <input type="radio" name="sShape" value="Pentagon" checked>Pentagon<br> 
    <input type="radio" name="sShape" value="Hexagon" checked>Hexagon<br> 
    <input type="radio" name="sShape" value="Heptagon" checked>Heptagon<br> 
    <input type="radio" name="sShape" value="Octagon" checked>Octagon<br> 
    <!--Set variable sShape equal to user's option.--> 

    <fieldset> 
     <legend>Spindle dimensions:</legend> 
     Height:<br> 
     <input type="text" name="tHeight"><br> 
     <!-- Text should only be positive integers greater than zero. Set variable tHeight equal to user's input. Must comply with ratios.--> 
     Width:<br> 
     <input type="text" name="tWidth"><br> 
     <!-- Same constraints as height apply. Set variable tWidth equal to user's input.--> 
     Depth:<br> 
     <input type="text" name="tDepth"><br> 
     <!-- Same constraints as height and width. Set variable tDepth equal to user's input.--> 
     Slant:<br> 
     <input type="text" name="tSlant"><br> 
     <!-- Text can be both positive and negative integers, as well as zero. Cannot exceed -80 or 80 degrees. Set variable tSlant equal to user's input.--> 
    </fieldset> 

    <input type="submit" name="Submit" value="Submit"> 

</form> 

(すなわち、["tBase"] => string(7) "Octagon")が、数値になると文字数がなくなり、数値が通らないことを意味します。誰かがこれで私を助けることができますか?ありがとうございました。

+0

良いコール。私は自分のコードをチェックして、私は重複があることが判明しました。 ...しかし、変数を変更しても0 x 0 x 0として表示されます。 –

+0

OK、私はあなたのコード全体を私にする必要はありませんでしたが、コードから必要なものを取り出しました。ありがとうございました。私は一例として取ったものを使って、他のすべてのものを自分でやり遂げることができます。 –

答えて

0

See inval()

説明

int intval (mixed $var [, int $base = 10 ]) 

変換に指定されたベースを(デフォルトはベース10)を用いて、varの整数値を返します。 intval()は、E_NOTICEレベルエラーを返して1を返すので、オブジェクトで使用しないでください。

あなたの入力が$_POST["value"]であれば、あなたが整数値を取得できます。

$integer_value = intval($_POST["value"]); 
+0

コードの行を既存のコードにコピー/ペーストしました。それは私がそれを置くとき次のメッセージを投げた:注意:未定義のインデックス:行9のC:\ XAMPP \ htdocs \ tower \ testfile_post.phpの値。そして前と同じことが起こった。このコードをどこに置くべきですか? –

+0

$ _POST ["value"]はプレースホルダです。 "value"を使用しようとしている実際の値に対応するキーの名前(フォームから)に置き換えてください。 –

+0

OK、これを試しました。今度は "0 x 0 x 0"として結果画面に登録しますが、入力する数字は何もありません。誰でもこの理由を知っていますか? –

関連する問題