jigsawsoul Posted January 24, 2010 Share Posted January 24, 2010 I'm using the below code below to check which checkboxes with selected in the last form page, when at least one is selected it works just fine but when none are selected i get the following error message display five times. Warning: Invalid argument supplied for foreach() in /home/hr728/public_html/_web/_admin/meeting/test2.php on line 16 <?php session_start(); include '../../_library/opendb.php'; include '../../_functions/login.php'; include '../../_functions/nav-admin.php'; $result = "SELECT * FROM web_staff LEFT JOIN web_login ON web_staff.login_id=web_login.login_id WHERE userlevel = '2' ORDER BY firstname ASC"; $result = mysql_query($result) or die( mysql_error() ); while($row = mysql_fetch_assoc($result)) { foreach($_POST["selectedstaff"] as $staff_id) { if ( $staff_id == $row['staff_id'] ) { //do all this ; echo $staff_id; } } } ?> Quote Link to comment Share on other sites More sharing options...
teamatomic Posted January 24, 2010 Share Posted January 24, 2010 You should check to see if the array exists or is empty. HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
jigsawsoul Posted January 24, 2010 Author Share Posted January 24, 2010 i'm not sure how to do this, i tried this below but still not luck <?php session_start(); include '../../_library/opendb.php'; include '../../_functions/login.php'; include '../../_functions/nav-admin.php'; $result = "SELECT * FROM web_staff LEFT JOIN web_login ON web_staff.login_id=web_login.login_id WHERE userlevel = '2' ORDER BY firstname ASC"; $result = mysql_query($result) or die( mysql_error() ); while($row = mysql_fetch_assoc($result)) { if (!=empty($_POST["selectedstaff"]) ){ foreach($_POST["selectedstaff"] as $staff_id) { if ( $staff_id == $row['staff_id'] ) { //do all this ; echo $staff_id; } } } } ?> Quote Link to comment Share on other sites More sharing options...
MidOhioIT Posted January 24, 2010 Share Posted January 24, 2010 try using this instead (isset($_POST["selectedstaff"]) ) 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.