Hello, I'm just starting to use PHP after years of working with ASP, so pardon me if this sounds like a very basic question, but how do I get PHP to acknowledge zero (0) in a form field. Whenever the user enters "zero" and hits submit on the PHP form, it totally ignores the zero.

I am inserting the value into a MYSQL database and I initially thought I was setting my field type wrong, but running the SQL command with zero through PHPAdmin inserts the zero without any problem. I then echo'ed the formfield and found that it wasn't posting the zero at all--

echo $_POST[$stepnow]; yeilds nothing
echo "$_POST[$stepnow]"; yeilds nothing

I've also tried all the convert to string functions I can find and I've seached the web for a solution--all with no results. It appears that PHP is simply discarding the zero during the POST process. Any suggestions?

7 Years
Discussion Span
Last Post by visualmonk

May help to post some more of your code.

But I assume you are running an empty() check on the POST vars?
From the PHP manual:

Returns FALSE if var  has a non-empty and non-zero value.

The following things are considered to be empty:

    * "" (an empty string)
    * 0 (0 as an integer)
    * "0" (0 as a string)
    * NULL
    * FALSE
    * array() (an empty array)
    * var $var; (a variable declared, but without a value in a class)

I would say in this case possibly use the isset() instead, this will return false on a NULL value, rather than a 0.

Otherwise, post the code so we can look.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.