Page 1 of 1

Foreach statement returing warning

Posted: Sun Nov 26, 2006 10:23 pm
by tecktalkcm0391
How come this:

Code: Select all

//line 12 is below:
foreach($_POST['message_checkbox'] as $num => $m_id){
					$sql = "DELETE FROM ".MESSAGES_TABLE." WHERE recipient = '".SESSION_USER."'
							AND folder = 'inbox' AND id = ".$m_id;
					$result = $database->query($sql);
				} // end foreach
keeps giving me this:
Warning: Invalid argument supplied for foreach() in /home/inbox.php on line 12

Posted: Sun Nov 26, 2006 10:25 pm
by feyd
Your post variable isn't an array.

Posted: Sun Nov 26, 2006 10:34 pm
by tecktalkcm0391
thanks didn't catch that..., but now my Javascript isn't working...

Code: Select all

<script language="JavaScript" type="text/javascript">
<!--
function function() {
 	if(document.inbox.mailaction.value=="foward"){
		var checked_total = 0;
		var max = document.inbox.message_checkbox[].length;
		for (var idx = 0; idx < max; idx++) {
		if (eval("document.inbox.message_checkbox[][" + idx + "].checked") == true) {
			checked_total += 1;
		   }
		}
		if(checked_total>1){
			alert("You selected " + checked_total + " messages, you can only foward one message at a time. Please only select one message.");
			return false;
		} else {
			return true;
		}
	}
	
}
-->
</script>
The checkboxes are named "message_checkbox[]"
so how can i get the Javascript to work now?

Note: I changed the JS to the current name of the checkboxes: "message_checkbox[]"

Posted: Sun Nov 26, 2006 10:39 pm
by feyd
Have a look through some of the more recent client side threads.

Posted: Sun Nov 26, 2006 10:54 pm
by tecktalkcm0391
Thanks....

But its still not working my new code is....

Code: Select all

<script language="JavaScript" type="text/javascript"> 
<!-- 
function function() { 
    if(document.inbox.mailaction.value=="foward"){ 
		var checkbox_name = document.getElementsByName('message_checkbox[]');
		var checked_total = 0;
		var max = checkbox_name.length;
		

I AM GETTIN THE PROBLEM 2 LINES AFTER HERE ( THE IF(EVAL...)

		for (var idx = 0; idx < max; idx++) {
			if (eval("" + checkbox_name + "[" + idx + "].checked") == true) {
				checked_total += 1;
			}
		}
		if(checked_total>1){
			alert("You selected " + checked_total + " messages, you can only foward one message at a time. Please only select one message.");
			return false;
		} else {
			return true;
		}
   } 
    
} 
--> 
</script>

Posted: Sun Nov 26, 2006 11:00 pm
by tecktalkcm0391
Never mind i got it i changed the messed up line to

Code: Select all

if (eval(checkbox_name[idx].checked) == true) {