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
imran.rajani
Forum Newbie
Posts: 16 Joined: Tue Dec 22, 2009 5:34 pm
Post
by imran.rajani » Wed Mar 03, 2010 8:44 pm
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.
moglimani
Forum Newbie
Posts: 18 Joined: Thu May 28, 2009 5:54 am
Post
by moglimani » Wed Mar 03, 2010 11:28 pm
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
Post
by fireproofsocks » Thu Mar 04, 2010 3:16 am
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?
imran.rajani
Forum Newbie
Posts: 16 Joined: Tue Dec 22, 2009 5:34 pm
Post
by imran.rajani » Thu Mar 04, 2010 11:11 am
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.
moglimani
Forum Newbie
Posts: 18 Joined: Thu May 28, 2009 5:54 am
Post
by moglimani » Fri Mar 05, 2010 4:05 am
ya........