Jump to content

ERROR: Warning: Invalid argument supplied for foreach() ????


jigsawsoul

Recommended Posts

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;
		}
	}
}
?>

 

 

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;
		    }
		    
		}
	}
}
?>

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.