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:

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

Beginner PHP code help
Hi I'm new to php but if someone could please read the question below and help it would be great.

Help with php code
Hello, can anyone tell me why this php word trap fails to work,
and the trigger words get blow r

newbie question
Hi out thereIm totaly new in this forum and to .net and vb so here is a totaly newbie question.I wan

Mail functionality from localhost to server
Hi

I am facing problem of mail functionality.

When i tested mail functionality in my

Update Database
Hi All,


I have a problem with this:

Code: [Select]<?php
session_start();

Warning message
I've put a website that I was doing live and I'm getting this warning message when I try to add a ne

Chat Box in PHP
I was thinking in doing a Chat Box in PHP. For that I would use a form with two fields, Nick and Mes

CE 7.1 and External GIS integration
Hi All,

We want to develop an application on CE 7.1 which uses GIS features from an exter

Convert .fdf to .pdf
I currently have a web form that uploads the form data to an .fdf file and emails it.

However

IF STATEMENT HELP
Hi
i have created a calendar from a table:

Code: Calendar: October 2009
<table w

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