Jump to content

Foreach from $_GET[]


proggR

Recommended Posts

$VAR = $_GET['topping'];
foreach($VAR as $key ){

echo $VAR;
echo $key;
}

Warning: Invalid argument supplied for foreach() in /var/www/order.php on line 25

Could someone tell me whats wrong with that code? Why I'm getting the error I'm getting I'm stumped. I want to be able to say if($key!=null) increment counter or something to that effect. Why is this not working? topping is a bunch of textboxes.  I just want to see if they're checked or not.

Anyway. The main concern is this code doesn't work and I can't figure out why not.

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/151346-foreach-from-_get/
Share on other sites

I get the error even when I know there is checkboxes checked. changed $VAR to $VAR[] and now when it prints I get Array mushrooms. It doesn't echo any of the other checkboxes. Mushrooms was the last checkbox checked. There are empty checkboxes after it though.

Link to comment
https://forums.phpfreaks.com/topic/151346-foreach-from-_get/#findComment-795155
Share on other sites

I read through that age and it didn't work either. So i changed the information being sent. The names are now "topping0", "topping1" etc and I have a for loop go through and check if its null and if not it increments the needed value and displays the contents like I need. This may also help me with a javascript event handler I'm working on within the form it gets sent from because now I can individually check and uncheck the boxes I need when certain buttons are pushed.

Thanks for everyone's help. It helped me realize what was going on.

Link to comment
https://forums.phpfreaks.com/topic/151346-foreach-from-_get/#findComment-795204
Share on other sites

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.