$number1 = $_POST['zombie'];
if ($number1 > 0){
echo "greater than 0";
}
现在我的脚本只是在$ _POST为-1时说它仍然大于0。 是否有一些代码检查0以下的值?
尝试#2:
$number1 = $_POST['number'];
if ($number1 > 0 && !($number1 < 0){
echo "greater than 0";
}
仍然无法工作......
echo gettype($ number1)返回:NULL
所以我做了&#34; print_r($ _ POST)&#34;
然后它返回:
Array
(
[zombie] => -1
[droid] => 0
[alien] => 0
[rpc] => 0
)
我的表格:
<form method="post" action="index.php">
<input type="number" class="form-control" value="0" name="zombie"> <br />
<input type="number" class="form-control" value="0" name="droid"> <br />
<input type="number" class="form-control" value="0" name="alien"> <br />
<input type="number" class="form-control" value="0" name="rpc"> <br />
</form
答案 0 :(得分:0)
也许您错误地发布了数据?检查$_POST['number']
中的内容。
echo $_POST['number'];
您可以随时查看整个$_POST
数组,也许您只是在变量名中犯了错误?如果你想这样做:
echo "<pre>";
print_r($_POST);
echo "</pre>";
您的代码中没有name="number"
的输入
你需要这样的东西:
<input type="number" class="form-control" value="0" name="number"> <br />
答案 1 :(得分:0)
<?php
if(isset($_POST['button']))
{
$number = $_POST['zombie'];
if($number > 0)
{
echo "number is greater";
}
else
{
echo "number is less";
}
}
?>
<form method="post" action="">
<input type="number" class="form-control" value="0" name="zombie"> <br />
<input type="number" class="form-control" value="0" name="droid"> <br />
<input type="number" class="form-control" value="0" name="alien"> <br />
<input type="number" class="form-control" value="0" name="rpc"> <br />
<input type="submit" name="button" value="submit">
</form>