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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.