Jump to content

This is strange. It won't insert "0" option value into table.


imgrooot

Recommended Posts

I am finding that if I have "0"(zero) value in form select option, it won't select this option or submit data.  If I change this value to any other number to text, it will work.  Is there a way to fix this?  I have to have an option where I am able to choose to submit "0" value to the database table.

<option value="0" <?php if(empty($_POST['special'])) {} else { if($_POST['special'] == 0) { echo 'selected'; } } ?> >None</option>
Link to comment
Share on other sites

 

that's because zero is considered to be "empty"

 

eg

$a = 0;
if (empty($a)) echo 'ok';  //--> ok

 

So what's the solution? The column I am inserting into is "int" based. So I need an int number to distinguish from all the other numbers.  Is there no way to add zero to it?

Link to comment
Share on other sites

All you have shown us is a single line of incorrect code and I pointed out what is wrong with that code.

 

You could try

<option value="0" <?php  if ($_POST['special'] === '0') echo 'selected';  ?> >None</option>

On the basis of a single line I can not and will not comment on an application solution, as I have no idea what the significance of the "0" versus "" is in the overall context. But your proposed alternative sounds wrong.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.