Demonic Posted March 26, 2008 Share Posted March 26, 2008 For some reason if say you set a input value to zero the value will output nothing when trying to echo, is this a bug or what? If you set the checkbox value to a negative or a positive greater then zero it displays the number fine. Just wondering, I found a work around using -1 and converting -1 to zero, but was wondering if this is normal for php to do? Link to comment https://forums.phpfreaks.com/topic/97998-does-php-checkbox-inputs-hate-the-number-0-zero-as-a-value/ Share on other sites More sharing options...
bpops Posted March 26, 2008 Share Posted March 26, 2008 I guess it sees the zero as NULL, and so when converting it to a string, it prints nothing. Perhaps you can typecast it to an INT before printing? Link to comment https://forums.phpfreaks.com/topic/97998-does-php-checkbox-inputs-hate-the-number-0-zero-as-a-value/#findComment-501401 Share on other sites More sharing options...
PFMaBiSmAd Posted March 26, 2008 Share Posted March 26, 2008 You would need to post your code. Is there a chance nothing was checked (which would give a null instead of a value) or that you are using the empty() function to test the value (zero is considered to be empty)? Link to comment https://forums.phpfreaks.com/topic/97998-does-php-checkbox-inputs-hate-the-number-0-zero-as-a-value/#findComment-501402 Share on other sites More sharing options...
Demonic Posted March 26, 2008 Author Share Posted March 26, 2008 I don't have the code handy with me on the fly( I'm at school ), but yeah this happened to me few times, say having an array of checkbox's <input name='del[]' value='0' /> <input name='del[]' value='1' /> <input name='del[]' value='2' /> <input name='del[]' value='3' /> <input name='del[]' value='4' /> Then when you go to check if a value is "set" and only the first checkbox is checked, nothing would be checked even if it was, so you really can't "typecast"(@the first post) the input value since it defeats the purpose of isseting the value if the value would tell the browser input "0" is always set, see what I'm talking about. Link to comment https://forums.phpfreaks.com/topic/97998-does-php-checkbox-inputs-hate-the-number-0-zero-as-a-value/#findComment-501411 Share on other sites More sharing options...
PFMaBiSmAd Posted March 26, 2008 Share Posted March 26, 2008 We would need to see your code. Either your form is not correct or your code that is echoing the value is not correct. Using an input like this - <input type="checkbox" name='del[]' value='0' /> Echos a zero using this code when the first checkbox is checked - echo $_POST['del'][0]; Nothing checked or a wrong variable name would give a NULL and echo nothing. Link to comment https://forums.phpfreaks.com/topic/97998-does-php-checkbox-inputs-hate-the-number-0-zero-as-a-value/#findComment-501427 Share on other sites More sharing options...
Demonic Posted March 26, 2008 Author Share Posted March 26, 2008 I forgot the type="checkbox" in my example sorry, but this has happened, I'll post the example when I get home. Link to comment https://forums.phpfreaks.com/topic/97998-does-php-checkbox-inputs-hate-the-number-0-zero-as-a-value/#findComment-501433 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.