Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2003
    Location
    India
    Posts
    3

    Unhappy Unanswered: Session is not working pls help me

    Dear all
    am new to php trying to save some data in session but when retreving i just getiing last inserted all other previous data are null.

    am using
    session_start() in all pages

    $ShoppingCart = array();
    f (!isset($_SESSION['Cart']))
    {
    $_SESSION['Cart'] = $ShoppingCart;
    }

    when adding to session

    $ShoppingCart = $_SESSION['Cart'];

    $temp = new ShoppedItem($_GET['accessid'],1,$row['Remarks'],$row['Price']);
    $ShoppingCart[count($ShoppingCart)+1] = $temp;

    $_SESSION['Cart'] = $ShoppingCart;

    ShoppedItem is a object i created.

    when display am using
    $ShoppingCart = $_SESSION['Cart'];
    foreach($ShoppingCart as $cart) {
    <? echo $cart->sName;?>
    ..... }

    please help me what to do

    thanks
    Sowmya

  2. #2
    Join Date
    Oct 2002
    Location
    Plymouth UK
    Posts
    116
    To user session variables you need to start the session, and you also need to register the variable. You can then use the variable. Like this:

    Code:
    session_start();
    session_register("test_var");
    
    $test_var = "some value";
    The registered variable 'test_var' can then be used across pages.

    I cannot see in your code that you register variables.

  3. #3
    Join Date
    Nov 2003
    Location
    India
    Posts
    3
    i given that too but am getting error

    Fatal error: Unknown(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition <b>shoppingcart</b> of the object you are trying to operate on was loaded _before_ the session was started in C:\Program Files\Apache Group\Apache2\htdocs\mybenz\shoppingcart.php on line 29


    session_register will work in new versions !!!

    i can get session now i cant get session variable as userdefined object ?

    i careated my own object but when getting from session i cant get it in my say

    how is it possible


    Originally posted by gannet
    To user session variables you need to start the session, and you also need to register the variable. You can then use the variable. Like this:

    Code:
    session_start();
    session_register("test_var");
    
    $test_var = "some value";
    The registered variable 'test_var' can then be used across pages.

    I cannot see in your code that you register variables.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •