bluebyyou Posted February 21, 2008 Share Posted February 21, 2008 I am trying to check for blank fields from a form, but this hasn't been working. For some reason $blanks isn't being incremented. What am I doing wrong? <?php foreach($_POST as $value) { if (empty($value)){ $blanks++; } } if ($blanks > 0) { //execute code } ?> Link to comment https://forums.phpfreaks.com/topic/92251-solved-checking-for-empty-fields-with-foreach/ Share on other sites More sharing options...
dave420 Posted February 21, 2008 Share Posted February 21, 2008 Are you sure your $_POST variable is being filled correctly? I tried it and it works for me... Link to comment https://forums.phpfreaks.com/topic/92251-solved-checking-for-empty-fields-with-foreach/#findComment-472612 Share on other sites More sharing options...
bluebyyou Posted February 21, 2008 Author Share Posted February 21, 2008 yeah i even did the print_r($_POST) to check, I have no idea what is happening. Link to comment https://forums.phpfreaks.com/topic/92251-solved-checking-for-empty-fields-with-foreach/#findComment-472616 Share on other sites More sharing options...
bluebyyou Posted February 21, 2008 Author Share Posted February 21, 2008 I figured it out as soon as I submitted that reply...I should have been putting if ($blanks == 0){} instead of: if ($blanks > 0){} I was having my code execute if there was blanks, instead of executing if there were no blanks, thanks for your help and sorry for the waste of time. Link to comment https://forums.phpfreaks.com/topic/92251-solved-checking-for-empty-fields-with-foreach/#findComment-472622 Share on other sites More sharing options...
dave420 Posted February 21, 2008 Share Posted February 21, 2008 That's cool! I was too busy trying to see why $blanks wasn't incrementing I'm glad you got it sorted. Link to comment https://forums.phpfreaks.com/topic/92251-solved-checking-for-empty-fields-with-foreach/#findComment-472627 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.