How to store checkbox array in a session, and then be able to add to it?


Posted on 16th Feb 2014 07:03 pm by admin

I'm trying to store an array of checkbox values into a session array, sort of like a shopping cart, but I can't figure out how to not overwrite the sessions array each time new checkbox values are added to the stored session...

Here is an array that is created upon submitting with two checkboxes checked:

Did you know?Explore Trending and Topic pages for more stories like this.
Code: Array
(
[0] => 606613
[1] => 606614
)
And then my sessions array is now like so:

Code: Array
(
[checked] => Array
(
[0] => 606613
[1] => 606614
)

)
The code for that so far is this:

<?php
if (!isset($_SESSION['checked'])) {
$_SESSION['checked'] = array();
}
$_SESSION['checked'] = $_GET['new_checked'];
?>

I know I probably need to add a loop that checks the arrays, but I just can't think how I should go about adding newly checked checkbox values, that are not duplicates, to the *end* of the session array "checked"??

Would anybody care to share some ideas?
No comments posted yet

Your Answer:

Login to answer
340 Like 33 Dislike
Previous forums Next forums
Other forums

how do I show what a user have selected from a checkbox?
From my code below, how would i show which check boxes have been checked and which radio buttons sel

noob question
i traying to do a php form with auto replay for both(me and the user who send me a mail),

a u

Database connection failure
Hello All,

I am trying to create new connection to Oracle DB 10.1,
I could not see a

Not Loading Function Into Div
I'm not sure whether to put this under the php forum or ajax forum but because I tink it's more of a

How do i use vars in an array
Hiya peeps!

How do I use a var in an array. You will see $id but it isnt working.


FlashVar function how to insert variables
Hi guys. Im new in this forum and also new in php programming. Can you help me about this code?
<

login and redirect
hello! can someone help me.. can you give me an idea.. I want to make a login page and redirects it

IP Based Cron Jobs
I run cronjobs on my website. After one of my visitors got curious and tinkered around he realized h

paginate search result
Hi, I have a paginations script to display data from my database but i would like to paginate someon

problems with script
I made a small script wich exchanges points in my website:


<?php
session_start

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash