kurv vha. serialize og unserialize
Jeg vil gerne forstå / træne i serialize og unserialize....Har derfor rodet med nedenstående.....(2 php filer)
Der kommer en fejl på side "Content.php" (kun ved første varevalg på index.php)...
Fejlen ses efterfølgende på content.php siden og lyder...
"Warning: Invalid argument supplied for foreach() in /home/www/eksperten.sluk.dk/shop1/content.php on line 22"
Er der et kvik hovede der kan hjælpe med at få disse to filer til at "spille sammen"?
Kan ses live her http://eksperten.sluk.dk
index.php----------------------------------------------------------------------------------
<?php session_start(); ?>
<html>
<head>
<title>Storing an array with a session</title>
</head>
<body>
<h1>Product Choice Page</h1>
<?php
if (isset($_POST['form_products'])) {
if (!empty($_SESSION['products'])) {
$products = array_unique(
array_merge(unserialize($_SESSION['products']), $_POST['form_products']));
}
if (!isset($_SESSION["products"])) { //Hvis sessionen ikke findes(ved første POST)
$_SESSION['products'] = array();// så opretter den en products SESSION(array)
}
$_SESSION['products'] = serialize($products);
print "<p>Your products have been registered!</p>";
}
?>
<form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
<P>Select some products:<br>
<select name="form_products" multiple size="8">
<option>Sonic Screwdriver</option>
<option>Hal 2000</option>
<option>Tardis</option>
<option>ORAC</option>
<option>Cat</option>
<option>Mercedes</option>
<option>Train</option>
<option>Transporter bracelet</option>
</select>
<br /><br />
<input type="submit" value="choose">
</form>
<br /><br />
<a href="content.php">content page</a>
</body>
</html>
content.php------------------------------------------------------
<?php session_start(); ?>
<html>
<head>
<title>Accessing session variables</title>
</head>
<body>
<h1> Content Page</h1>
<?php
if(isset($_POST['reset'])){
session_unset();}
echo "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">";
echo "<input type=\"submit\" name=\"reset\" value=\" Empty session \" />";
echo "</form>";
if (isset($_SESSION['products'])) {
echo "<b>Your cart:</b><ol>\n";
foreach (unserialize($_SESSION['products']) as $p) {
echo "<li>$p";
}
echo "</ol>";
}
?>
<a href="index.php">Back to product choice page</a>
</body>
</html>
