Hey all, right now I'm having some problems combining sessions and the simplexml_load_file function. The error I get?
Warning: session_start() [ function.session-start]: Node no longer exists in myLocation on line 1
I Googled it, and found that it's a fairly well-known problem/bug. Apparently sessions don't like storing XML information. Lots of people have their own fixes, but I can't get anything to work. Here's the code I'm using:
PHP Code:
$filename = 'products.xml'; $xmlstr = file_get_contents($filename); $xml_data = simplexml_load_string($xmlstr);
$products = array(); $_SESSION['cart'] = array();
foreach ($xml_data->product as $product) { $id = $product->id; $name = $product->name; $description = $product->description; $image = $product->image; $price = $product->price;
$status = "";
if($_POST['cart'.$id]) { $status = "Product added"; array_push($_SESSION['cart'],$id); }
$products[] = " <div class='product'> <h5>".$id."</h5> <h3>".$name."</h3> <p>".$description."</p> <p>".$image."</p> <h4>".$price."</h4> <form action='?' method='POST'> <input type='submit' value='Add to cart' name='cart".$id."' /> </form> ".$status." </div>"; }
foreach($products as $content) { echo $content; } foreach($_SESSION['cart'] as $sessions) { echo $sessions; }
And, of course, I have a session_start() at the beginning of the page before the <html> tag. Do you have any fix that would work with this code?
Thanks.
__________________
if($stevej == "helpful") { $talkupation += $user_power; }
|