/    Sign up×
Community /Pin to ProfileBookmark

Problems with sessions and array

Hi!

From voting page I sent a value like this <a href=”?p=add&id={$id}”>YES</a>

And from $_GET I then want to add the value into $_SESSION[‘myVotes’][] = $id; that I have declared as an session array like this
$votes = array();
$_SESSION[‘myVotes’]= $votes; this is done in the index.php and only done once.

The process of adding to the session array is done on a page and then return back to the page from where the voting was done. I add to the session array like this $_SEESION[‘myVotes’][] = $id.The problem is that the array just replace the first value and not growing to a list of added numbers between the pages! Why this and what have I done wrong? Preciate some help! Thanks!

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 18.2011 — I can't tell for sure without seeing the actual code. I'd suggest doing a var_dump() or print_r() on $_SESSION and any other arrays/variables of interest and look for anything "interesting". And don't forget you need a session_start() on each page before doing [i]anything[/i] with $_SESSION.
Copy linkTweet thisAlerts:
@pkngauthorJan 18.2011 — Hi,

I use session_start() on each page and I have used print_r() and on the voting process page the last value is in the array, but when I use print_r() on the voting page it's not there!

Sorry but it's to complicated and to much code to show here! Could the problem has to do with redirecting? From the voting process page, back to voting page I use header("Location:?p=visa&id={$id}"); ??

The strange thing is that thoose values I added from the beginning in the array hangs around the pages in the session?!

Still hoping to find the error ??
Copy linkTweet thisAlerts:
@criterion9Jan 18.2011 — Hi,

I use session_start() on each page and I have used print_r() and on the voting process page the last value is in the array, but when I use print_r() on the voting page it's not there!

Sorry but it's to complicated and to much code to show here! Could the problem has to do with redirecting? From the voting process page, back to voting page I use header("Location:?p=visa&id={$id}"); ??

The strange thing is that thoose values I added from the beginning in the array hangs around the pages in the session?!

Still hoping to find the error ??[/QUOTE]

It would be pure speculation for any of us to make suggestions without seeing any of the troubled code.
Copy linkTweet thisAlerts:
@pkngauthorJan 18.2011 — I have solved it on my own! ?
×

Success!

Help @pkng spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...