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
Link to comment
Share on other sites

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[]
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.