Connecting Tech Pros Worldwide Forums | Help | Site Map

$_SESSION $_POST

Quinonez
Guest
 
Posts: n/a
#1: Jul 17 '05
i set up a multipage form about a month ago using Sessions everything
worked well and i moved forward with working on other pages i just
checked the form to make sure it is all working properly and its giving
me an error:

Warning: Invalid argument supplied for foreach() in
/home/mastersc/public_html/testthis.php on line 24

this is the code:

<?
ksort($_SESSION);
foreach ($_SESSION as $page=>$_POST)
{
echo "<div class=\"h3\">$page</div><br>";
foreach ($_POST as $field=>$value) <--this would be line 24-->
{
echo "$field: $value<br>";
}
}
?>

any suggestions?

Kevin
Guest
 
Posts: n/a
#2: Jul 17 '05

re: $_SESSION $_POST


Try doing a var_dump or print_r of $_SESSION before your for loop.

I suspect that there's a key => value pair where the value isn't an array.

- Kevin

"Quinonez" <quinonez@gmail.com> wrote in message
news:1105480688.597766.43520@c13g2000cwb.googlegro ups.com...[color=blue]
>i set up a multipage form about a month ago using Sessions everything
> worked well and i moved forward with working on other pages i just
> checked the form to make sure it is all working properly and its giving
> me an error:
>
> Warning: Invalid argument supplied for foreach() in
> /home/mastersc/public_html/testthis.php on line 24
>
> this is the code:
>
> <?
> ksort($_SESSION);
> foreach ($_SESSION as $page=>$_POST)
> {
> echo "<div class=\"h3\">$page</div><br>";
> foreach ($_POST as $field=>$value) <--this would be line 24-->
> {
> echo "$field: $value<br>";
> }
> }
> ?>
>
> any suggestions?
>[/color]


Andy Hassall
Guest
 
Posts: n/a
#3: Jul 17 '05

re: $_SESSION $_POST


On 11 Jan 2005 13:58:08 -0800, "Quinonez" <quinonez@gmail.com> wrote:
[color=blue]
>i set up a multipage form about a month ago using Sessions everything
>worked well and i moved forward with working on other pages i just
>checked the form to make sure it is all working properly and its giving
>me an error:
>
>Warning: Invalid argument supplied for foreach() in
>/home/mastersc/public_html/testthis.php on line 24
>
>this is the code:
>
><?
>ksort($_SESSION);[/color]

Is session.auto_start turned on? Shouldn't you call session_start() first?
[color=blue]
>foreach ($_SESSION as $page=>$_POST)[/color]

This seems a little odd - you're overwriting the superglobal variable $_POST
with the contents of the session array values?
[color=blue]
>{
>echo "<div class=\"h3\">$page</div><br>";
>foreach ($_POST as $field=>$value) <--this would be line 24-->[/color]

The error basically implies $_POST is not an array at this point. Dump it out
with var_dump/print_r, along with $_SESSION from earlier.
[color=blue]
>{
> echo "$field: $value<br>";
> }
>}
>?>
>
>any suggestions?[/color]

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Closed Thread


Similar PHP bytes