phprocker Posted November 14, 2010 Share Posted November 14, 2010 Hey all. I have a page that dynamically creates form input fields called "menuitem[]". So on the page that checks the values I need to check if any of those fields were not filed in. My syntax is wrong any help would be great. test.php foreach($_POST['menuitem'] as $key => $value) { if(!isset($value) || $value = "") { echo "Please fill in all values. You left key " . $key . "empty."; } } Nothing gets echoed when I leave the fields empty so I'm doing something wrong here. Link to comment https://forums.phpfreaks.com/topic/218610-check-if-array-value-isset/ Share on other sites More sharing options...
s0c0 Posted November 14, 2010 Share Posted November 14, 2010 Needs to be: if(!isset($value) || $value == "") You used a bad equality operator, common mistake. I would also use empty($value) as $value will always be set. Also wrap you foreach in an if(is_array($_POST['menuitem'])) as an unforseen error may pass over a non-array and you will want to account for that, else you'll get a warning looping through it. Link to comment https://forums.phpfreaks.com/topic/218610-check-if-array-value-isset/#findComment-1133963 Share on other sites More sharing options...
phprocker Posted November 14, 2010 Author Share Posted November 14, 2010 UHHGG, I hate it when I do that! Thanks a bunch. Link to comment https://forums.phpfreaks.com/topic/218610-check-if-array-value-isset/#findComment-1133999 Share on other sites More sharing options...
fonor Posted November 21, 2010 Share Posted November 21, 2010 i have same problem ever, try to use empty() function, make it easy and professional Link to comment https://forums.phpfreaks.com/topic/218610-check-if-array-value-isset/#findComment-1137434 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.