Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: sessions in php

  1. #1
    New to the CF scene
    Join Date
    Mar 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    sessions in php

    I was trying to append some values in already exists session.

    Code:
    if(isset($_SESSION['ems_id']) == NULL) {
        echo "empty";
        $_SESSION['ems_id'] = "0";
        $_SESSION['ems_amt'] = "0";
                 }
      
    $ix = count($_SESSION['ems_id']);
    $ix++;
     
    $_SESSION['ems_id'][5] = strval($rowEms['hs_id']);
    $_SESSION['ems_amt'][5] = strval($rowBuy2['hs_ems']);
    Its not working
    Session stores new data but not populates - Just replacing.

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    its replacing the value because you've hard-coded the slot in the array where you're storing the information.

    $_SESSION['ems_id'][5] = strval($rowEms['hs_id']);
    $_SESSION['ems_amt'][5] = strval($rowBuy2['hs_ems']);


    will always store the info in the same place, thereby overwriting whatever was stored there before.

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION


  •  

    Posting Permissions

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