It is currently Fri Mar 29, 2024 5:55 am


All times are UTC


Forum rules


Please click here to view the forum rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: $_SESSION with foreach
PostPosted: Sat Feb 18, 2006 6:06 pm 
Noobie
Noobie

Joined: Mon Oct 17, 2005 1:14 am
Posts: 3
Hi i have built my own small shopping cart which works fine on my local apache server but when i try it on my host i get this error...

Invalid argument supplied for foreach()

so i wrote a small script to test this here it is..

$_SESSION['cart'][76] = 2;



if(isset($_SESSION['cart'])) {

foreach($_SESSION['cart'] as $key => $value) {
if(isset($value)) {
$empty = FALSE;
echo $value . $key;
}
}
}


which also works again on my local server but when i upload and test i get the same foreach() error i have seacrhed all over for ages looking for a solution but cant find on anywere so any help would be brilliant

thanks


Top
 Profile  
 
 Post subject: Kinky...
PostPosted: Sat Feb 18, 2006 8:06 pm 
Noobie
Noobie

Joined: Wed Feb 08, 2006 11:32 pm
Posts: 12
Hum, that test script works just fine here on my 100WebSpace account...

Perhaps session.auto_start is off? Try starting the session manually with session_start(). Also, try stating explicitly that $_SESSION['cart'] is an array:
Code:
<?php

$_SESSION['cart'] = array();
$_SESSION['cart'][76] = 2;

foreach( $_SESSION['cart'] as $key => $var ) {
  if( isset( $var ) ) {
    echo "Cart $key contains $var. <br>\n";
  }
}

?>


Other than that, I'm out of ideas right now..


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ]  Moderators: fhmagic, KJ, Moderators, Support Team

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
100WebSpace © 2011