This is what you recommended.

Is there a reason you're using a comma delimited string? I would
recommend using an array instead:
<?php
session_name( 'CCLTrolley' );
session_start();
// Initialize the trolley.
if( !isset( $_SESSION['TrolleyContents'] ) )
{
$_SESSION['TrolleyContents'] = array();
}
// Add new entry.
if( isset( $_POST['AddToTrolley'] ) )
{
$_SESSION['TrolleyContents'][$_POST['AddToTrolley']] =
$_POST['AddToTrolley']
}
echo implode( ',', $_SESSION['TrolleyContents'] );
phpinfo();
?>

This is what I implemented? Where did I go wrong?
John

<?php
session_name( 'CCLTrolley' );
session_start();

// Initialize the trolley.
if( !isset( $_SESSION['TrolleyContents'] ) )
{
   $_SESSION['TrolleyContents'] = array();
}

if("add" == $_POST['ShopAction'])
{
   // Add new entry:
   if( isset( $_POST['RNum'] ) )
   {
       $_SESSION['TrolleyContents'][$_POST['RNum']] = $_POST['RNum'];
   }
   echo implode( ',', $_SESSION['TrolleyContents'] );
}else{
   //Delete an entry:
   if( isset( $_SESSION['TrolleyContents'][$_POST['RNum']] ) )
   {
   #    $_SESSION['TrolleyContents'][$_POST['RNum']] -= 1;
   #    if( $_SESSION['TrolleyContents'][$_POST['RNum']] <= 0 )
   #    {
           unset( $_SESSION['TrolleyContents'][$_POST['RNum']] );
   #    }
   }
}
print_r( $_SESSION );
#phpinfo();
?>

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

Reply via email to