2016-08-05 23 views
0

好的,所以我有一个我正在尝试创建的网站的表单。我试图将来自HTML的用户输入存储到字符串值中以显示在PHP中。麻烦的是,当我输入数字值时,我无法识别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> 

我有什么至今在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阵列中的字符数形状(即[“tBase”] =>字符串(7)“八角形”),但是对于数字值来说,没有字符计数,这意味着数值没有通过。任何人都可以帮我解决这个问题吗?谢谢。

+0

良好的通话。我检查了我的代码,结果证明我有重复。 ...但即使是变化的变化,它仍然显示为0 x 0 x 0. –

+0

好的,我不需要你为我完成整个代码,但是我从代码中获取了所需的代码。谢谢。我可以自己完成所有其他事情,例如使用我所做的一切。 –

回答

0

See inval()

说明

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

返回var整数值,使用用于转换指定基本(默认为10为底)。 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

好的,我试了一下。现在它在结果屏幕上注册为“0 x 0 x 0”,不管我输入什么号码。任何人都知道这可能是为什么? –

相关问题