• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

zero value problem

harrylmh

New Member
I found a problem when dealing with zeros in forms. Post values containing 0 just won't be not empty.

Check this script:
PHP:
<?php
if (empty($HTTP_POST_VARS["choose"]))
	echo "No value<br>";
else
{
	echo "There's a value! - $HTTP_POST_VARS[choose]<br>";
}
?>
<form method="post" action="got_value.php">
	<select name="choose">
		<option value="0">Zero</option>
		<option value="1">One</option>
	</select>
	<input type="submit" value="submit">
</form>

Try selecting Zero and submit. Then try One.

What's the problem???

Thank you.
 
Here use this
PHP:
<?php
if (isset($HTTP_POST_VARS["choose"]) || $HTTP_POST_VARS["choose"] == "0") {
    echo "There's a value! - $HTTP_POST_VARS[choose]<br>";
} else {
    echo "No value<br>";
}
?>
<form method="post" action="test.php">
    <select name="choose">
        <option value="0">Zero</option>
        <option value="1">One</option>
    </select>
    <input type="submit" value="submit">
</form>
 
Back
Top