low-rider Posted April 4, 2007 Share Posted April 4, 2007 hi, i have an array of food names and im using $_SESSION to pass the variables to another php. if i enter foreach($_SESSION["food"] as $foodNames) { echo $foodNames"; } i get en error saying Invalid argument supplied for foreach() what am i doing wrong??? Link to comment https://forums.phpfreaks.com/topic/45554-foreach-loop-and-_session/ Share on other sites More sharing options...
monk.e.boy Posted April 4, 2007 Share Posted April 4, 2007 do a print_r( $_SESSION ); to see what is in the session. But I expect you have forgotten: session_start() -- http://uk3.php.net/function.session-start monk.e.boy Link to comment https://forums.phpfreaks.com/topic/45554-foreach-loop-and-_session/#findComment-221157 Share on other sites More sharing options...
low-rider Posted April 4, 2007 Author Share Posted April 4, 2007 do a print_r( $_SESSION ); to see what is in the session. But I expect you have forgotten: session_start() -- http://uk3.php.net/function.session-start monk.e.boy session_start() is declared at the very top of my page.... this is what i have at the top: <?php session_start(); $_SESSION["food"] = $food; $fullName=$_GET["fullName"]; $houseNN=$_GET["houseNN"]; $streetName=$_GET["streetName"]; $town=$_GET["town"]; $county=$_GET["county"]; $postCode=$_GET["postCode"]; $country=$_GET["country"]; ?> this is where i want to echo array FOOD! and underneath in a table, i have the foreach loop! Link to comment https://forums.phpfreaks.com/topic/45554-foreach-loop-and-_session/#findComment-221164 Share on other sites More sharing options...
monk.e.boy Posted April 4, 2007 Share Posted April 4, 2007 so did you do the: do a print_r( $_SESSION ); to see what is in the session. monk.e.boy Link to comment https://forums.phpfreaks.com/topic/45554-foreach-loop-and-_session/#findComment-221183 Share on other sites More sharing options...
low-rider Posted April 4, 2007 Author Share Posted April 4, 2007 this is what i got Array ( [food] => [QHat] => 1 [QBag] => 1 [QBall] => 1 [product] => poo ) Link to comment https://forums.phpfreaks.com/topic/45554-foreach-loop-and-_session/#findComment-221188 Share on other sites More sharing options...
kenrbnsn Posted April 4, 2007 Share Posted April 4, 2007 That's telling you that $_SESSION['food'] is set to nothing. Please show us the code where you set the session variable. Also, if you dump the $_SESSION array with <?php echo '<pre>' . print_r($_SESSION,true) . '</pre>'; ?> the output is much more readable. Ken Link to comment https://forums.phpfreaks.com/topic/45554-foreach-loop-and-_session/#findComment-221203 Share on other sites More sharing options...
monk.e.boy Posted April 4, 2007 Share Posted April 4, 2007 $_SESSION["food"] = $food; I expect $food is null. monk.e.boy Link to comment https://forums.phpfreaks.com/topic/45554-foreach-loop-and-_session/#findComment-221209 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.