sessions in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
imran.rajani
Forum Newbie
Posts: 16
Joined: Tue Dec 22, 2009 5:34 pm

sessions in php

Post by imran.rajani »

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

Code: Select all

 
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.
User avatar
moglimani
Forum Newbie
Posts: 18
Joined: Thu May 28, 2009 5:54 am

Re: sessions in php

Post by moglimani »

here is the result...

Code: Select all

 
if(isset($_SESSION['ems_id']) == NULL) {
    echo "empty";
    $_SESSION['ems_id'] = "0";
    $_SESSION['ems_amt'] = "0";
             }
 
$ix = count($_SESSION['ems_id']);
 
 
$_SESSION['ems_id'][$x+1] = strval($rowEms['hs_id']);
$_SESSION['ems_amt'][$x+1] = strval($rowBuy2['hs_ems']);
 
now check
fireproofsocks
Forum Newbie
Posts: 4
Joined: Thu Mar 04, 2010 3:04 am

Re: sessions in php

Post by fireproofsocks »

This is redundant:

Code: Select all

if(isset($_SESSION['ems_id']) == NULL) {
Why not just

Code: Select all

if(isset($_SESSION['ems_id']) ) {
?

The $_SESSION array works just like any other array. How would you update this value in some other array?
imran.rajani
Forum Newbie
Posts: 16
Joined: Tue Dec 22, 2009 5:34 pm

Re: sessions in php

Post by imran.rajani »

moglimani wrote:here is the result...

Code: Select all

 
if(isset($_SESSION['ems_id']) == NULL) {
    echo "empty";
    $_SESSION['ems_id'] = "0";
    $_SESSION['ems_amt'] = "0";
             }
 
$ix = count($_SESSION['ems_id']);
 
 
$_SESSION['ems_id'][$x+1] = strval($rowEms['hs_id']);
$_SESSION['ems_amt'][$x+1] = strval($rowBuy2['hs_ems']);
 
now check
I saw what you changed, i was actually testing.

I found reason i.e.
In the IF block i was assigning scalar values to $_SESSION['ems_id'] and $_SESSION['ems_amt'], so those array elements are not arrays themselves, but then trying to assign array elements to them in the last two lines. So I changed as ;

if(isset($_SESSION['ems_id']) == NULL) {
echo "empty";
$_SESSION['ems_id'][0] = "0";
$_SESSION['ems_amt'][0] = "0";
}

Thank you guys for help.
User avatar
moglimani
Forum Newbie
Posts: 18
Joined: Thu May 28, 2009 5:54 am

Re: sessions in php

Post by moglimani »

ya........
Post Reply