Jump to content

why am i getting problems with this foreach loop


predator

Recommended Posts

hey i got this for each loop

if($_POST['remove']){
foreach($_POST['remove'] as $k=>$v){
mysql_query("DELETE FROM sections WHERE id='$v' LIMIT 1");
}
}

and i am getting the error of

Warning: Invalid argument supplied for foreach()

the $_POST['remove'] is an array i get from an html page and it has a products id assigned to it

but i just cant work out why this is giving me an error.

any help greatly apprechiated

Regards
Mark
If you are getitng that error then $_POST['remove'] is not an array. Try this code:
[code=php:0]echo '<pre>' . print_r($_POST['remove'], true) . '</pre>';[/code]

What does that return?

Also if you have input fields that have the same name as remove make sure you have add the square brackets after the name, eg: remove[]
yes it is an array the name of each check box is
remove[{$content[i].id}]

where $content is obviously the id that will be passed into each remove element.

personally i dont like this way of coding however i have taken this project over at work and cant totally re write the code as the customer needs it done obviously sooner than later

regards
Mark

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.