Page 1 of 1
sessions in php
Posted: Wed Mar 03, 2010 8:44 pm
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.
Re: sessions in php
Posted: Wed Mar 03, 2010 11:28 pm
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
Re: sessions in php
Posted: Thu Mar 04, 2010 3:16 am
by fireproofsocks
This is redundant:
Code: Select all
if(isset($_SESSION['ems_id']) == NULL) {
Why not just
?
The $_SESSION array works just like any other array. How would you update this value in some other array?
Re: sessions in php
Posted: Thu Mar 04, 2010 11:11 am
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.
Re: sessions in php
Posted: Fri Mar 05, 2010 4:05 am
by moglimani
ya........