//filename - test.php
<?php
$test=$_POST["test"];
if(!isset["post"]))
{
echo '
<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="test.php">
Check1: <input type="checkbox" name="test[]" value="check1"/>
Check2: <input type="checkbox" name="test[]" value="check2"/>
<input type="submit" value="post"/>
</form>
</body>
</html>';
}
else
{
foreach($test as $t)
{
echo $t . "";
}
}
?>
Problem description:
When I run my script the first time, everything is fine. I check my checkboxes and hit submit.
However, after I hit submit, it tells me I called foreach() wrong.
Heres the exact error -
Warning : invalid argument supplied for foreach() in [blah blah blah] on line [whatever line foreach() is called on].
What am I doing wrong?
Thankyou for your help if I don't thank you for a response.
You're missing out a single } after foreach.
There is a good reason people use indentation when they are coding and that is because it makes it a lot easier to notice these sorts of problems.
As you can see, the problem would have been much easier to see had you done that in the first place.