Anthony Ritter wrote:

> The following code is from "PHP, mySQL and Apache" (SAMS) by Julie Meloni.
[snip]
> if (isset($_POST[form_products])) {
>     if (!empty($_SESSION[products])) {
>         $products = array_unique(
>         array_merge(unserialize($_SESSION[products]),
> $_POST[form_products]));
>    }
> $_SESSION[products] = serialize($products);

I know you're working from a book, but for future reference, there's no
reason to serialize $products before storing it in the session. The whole
session array is going to be serialized at the end of the script, anyhow.
You can assign it directly to the session as an array and work with it as an
array on the following pages, too.

if (isset($_POST[form_products])) {
    if (!empty($_SESSION[products])) {
        $products = array_unique(
        array_merge($_SESSION[products],
$_POST[form_products]));
   }
$_SESSION[products] = $products;

Then to recreate your $products array on other pages, you can either go the
easy route and just use the $_SESSION['products'] array... or use:

$products = $_SESSION['products'];

There's really no reason to have a $products variable to begin with,
actually. You can work directly with the $_SESSION['products'] variable,
adding and removing things from it and it'll always be available...

---John Holmes...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to