emiel popelier emiel popelier - 1 month ago 9
PHP Question

check if value is above 0 not working

$number1 = $_POST['zombie'];
if ($number1 > 0){
echo "greater than 0";
}


Now my script just says when the $_POST is -1 that it still is greater than 0.
Is there some code that checks for values under 0?

Try #2:

$number1 = $_POST['number'];
if ($number1 > 0 && !($number1 < 0){
echo "greater than 0";
}


Still doesn't work...

echo gettype($number1) returns: NULL

So i did the "print_r($_POST)"

and it returns:

Array
(
[zombie] => -1
[droid] => 0
[alien] => 0
[rpc] => 0
)


my form:

<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

Answer

Maybe you just wrong posting your data? Check what is in $_POST['number'].

echo $_POST['number'];

You can always check your whole $_POST array, maybe you just made a mistake in your variable name? If you want to do it:

echo "<pre>";
print_r($_POST);
echo "</pre>";

There is no input in your code with name="number" You need something like that:

<input type="number" class="form-control" value="0" name="number"> <br />