PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
becky-atlanta
Forum Commoner
Posts: 74 Joined: Thu Feb 26, 2009 6:26 pm
Location: Atlanta, GA
Post
by becky-atlanta » Tue Mar 31, 2009 1:16 pm
I am getting ...Invalid argument supplied for foreach()...
Code: Select all
foreach ($_POST["week"] as $wk) {
fwrite($fh, $wk);
fwrite($fh, "<br>\n");}
I was using the same code in another page and it was working fine.
Any advice?
estamand
Forum Newbie
Posts: 7 Joined: Sat Mar 21, 2009 1:28 pm
Post
by estamand » Tue Mar 31, 2009 1:48 pm
Have you tried to use single quotes for your $_POST?
Code: Select all
1. foreach ([color=#BF0000]$_POST['week'][/color] as $wk) {
2. fwrite($fh, $wk);
3. fwrite($fh, "<br>\n");}
becky-atlanta
Forum Commoner
Posts: 74 Joined: Thu Feb 26, 2009 6:26 pm
Location: Atlanta, GA
Post
by becky-atlanta » Tue Mar 31, 2009 1:58 pm
I tried and still got the same error.
estamand
Forum Newbie
Posts: 7 Joined: Sat Mar 21, 2009 1:28 pm
Post
by estamand » Tue Mar 31, 2009 2:19 pm
Sure you aren't missing a ; above the for each?
Sorry i can't help you more.
becky-atlanta
Forum Commoner
Posts: 74 Joined: Thu Feb 26, 2009 6:26 pm
Location: Atlanta, GA
Post
by becky-atlanta » Tue Mar 31, 2009 2:38 pm
Thanks for trying. I have been checking it, and checking it, and checking it for over a day and have not found out why it is not working. Like I said, it is working fine on another page.
dead leprachorn
Forum Newbie
Posts: 6 Joined: Tue Mar 31, 2009 10:08 am
Post
by dead leprachorn » Tue Mar 31, 2009 2:47 pm
the "error invalid argument supplied" suggests you are not performing foreach() on an array. Have you checked that you are referencing the correct variable | sending the data properly? a null value will result in an invalid argument supplied error.
Code: Select all
<?php
foreach($empty as $empt) {
}
?>
will result in..
Code: Select all
Warning: Invalid argument supplied for foreach() in /.../error.php on line 2
becky-atlanta
Forum Commoner
Posts: 74 Joined: Thu Feb 26, 2009 6:26 pm
Location: Atlanta, GA
Post
by becky-atlanta » Tue Mar 31, 2009 2:56 pm
I suspected the variable created the issue. Thanks for confirming it. I will check/redo the form again and try.
estamand
Forum Newbie
Posts: 7 Joined: Sat Mar 21, 2009 1:28 pm
Post
by estamand » Tue Mar 31, 2009 3:26 pm
You can always check to make sure it is array with is_array before your opperation.
becky-atlanta
Forum Commoner
Posts: 74 Joined: Thu Feb 26, 2009 6:26 pm
Location: Atlanta, GA
Post
by becky-atlanta » Tue Mar 31, 2009 9:41 pm
Since you reply, I'll tell you what I did wrong.
I had this in the code and that messed things up.
<?php echo $PHP_SELF ?>
After I changed it to
<?php $PHP_SELF ?>
everything works fine.
Now, I will always remember it.
estamand
Forum Newbie
Posts: 7 Joined: Sat Mar 21, 2009 1:28 pm
Post
by estamand » Tue Mar 31, 2009 10:56 pm
Glad you figured it out Becky. It always turns out to be something silly.