Skip to content
Advertisement

why select option value if zero post empty

I am sorry bad English. I have a select menu option value problem:

<select>
   <option value=0>element1</option>
   <option value=1>element2</option> 
</select> 

I am if select value="0" option and this post, it retuns the value with no problem. But, when I use value = 0 save mysql table, this value not 0 this return empty. This value saving column type integer? What is problem?

I am not using mysql_real_escape_string or any filter. If select value="1" option no problem, it is saving succesfully.

Thanks

Advertisement

Answer

I ran into this issue myself and what I found was that when posting option/select box values and reading them with PHP, when the ‘value’ of it was 0 it was acting like I did not post at all because I was checking to see anything had been posted like this:

if ($_POST['status']) {
    // do stuff here
}

When in fact I needed to check it using isset(), because the way shown above returns false even if the value is 0. The example shown below checks to see if it really is set at all, even if the value is 0.

if (isset($_POST['status'])) {
    // do stuff here
}

You did not show us your PHP code so I am only guessing this was also your problem.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement