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?

Recommended Answers

All 2 Replies

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.

Thanks Will, changing to ISSET solved the problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.