Checkboxes save variables to a session then displayed on another page

Hi,

I have been racking my brains for days with this and searched many forums etc but just cant find the solution.
I have a form and part of that form is using checkboxes. Like as displayed below:
[php]




[/php]
I want to be able save the the boxes that become checked into a session so I can recall them later when needed. Would anyone please help me work out how to accomplish this so they are saved into a session and then teach me the code to call them on other pages. Session start is already on all pages.

I did it have it working for a bit but it would only paste “Array” into the editbox. But all that code got deleted in a fit of frustration so I am back to the drawing board.

Many thanks in advance.

What are you currently working with, as in your code?

then teach me the code to call them on other pages

This sounds an awful lot like, do it for me “then I will understand how.”

If you did have it working, then what did you do originally?

Array will show, because there are many of them. You would need to serialize the data for one.

Hi astonecipher,

Basically I am making an event booking form. I use a wysiwyg editor and paste all my html around it- I will get it back to the point where it is posting the session variable again as “Array” on the next page and then go from that if you dont mind helping.

I am assuming if it is posting the word Array on the next page then the Array is populated but just not calling the array places ie array[0] array[1] etc

Basically. It is expecting an array to be passed, you you need to iterate through the array, or use a single index.

[php]


Select one Ticket NoTicket Subscribed <?php if(isset($_POST['eventtype'])){echo $_POST['eventtype'];{$_SESSION['eventtype'] = $_POST['eventtype'];}}?>"> Adult Men
Adult Women
Children Boys
Children Girls
<?php foreach ($_POST['NewCategory'] as $key => $value){$_SESSION["NewCategory"] = $_POST["NewCategory"];}?>
Link to Success Page
[/php]

Start of page =
[php]<?php
if (isset($_SESSION[“NewCategory”])) {
echo “
”;
foreach ($_SESSION[‘NewCategory’] as $value)
echo "Your games are: " . $_SESSION[“NewCategory”];
}
?>[/php]
Please put the code in tags there’s a php button at the top — Strider

Then I try and call the value to an edit box:

But I just get Array sorry for double post I clicked by accident

It looks like your hijacking someone’s thread, but it’s hard to tell. :o

Sorry Strider - future posts with code I will put in the php buttons.

Not hijacking any threads - Just trying to get this done - I cant believe how difficult this is turning out to be.

Nope. Started as a guest, we really need to discuss that feature, and registered so they could interact for the response.

The way the code is done currently, you will throw errors for unknown indexes.

I have some testing to do…

You foreach statement is incorrect:

[php] <?php if (isset($_SESSION["NewCategory"])) { echo "
"; foreach ($_SESSION['NewCategory'] as $value) echo "Your games are: " . $_SESSION["NewCategory"]; } ?>[/php]

Compared to:

[php] <?php if (isset($_SESSION["NewCategory"])) { echo "
"; foreach ($_SESSION['NewCategory'] as $value) echo "Your games are: " . $value; } ?>[/php]

By the way, formatting your code will make it far easier to read and debug when there are problems.

Cool thanks for your help in pointing out the issue is with my arrays.

Once I come up with a solution that works I’ll post it back here as to help others with the same issue :slight_smile:

Back to testing for me too :wink:

astonecipher thanks for your help sir it works perfectly. I cant believe I douched that up - I had given up for this evening and turned to beer and game of thrones when I saw you replied I had to quickly try it out. Sorry about my formatting (You should see other stuff I have written if you think this is bad :-[ )

I owe you a beer and clocked your donate button :wink:

Glad I could help and I appreciate it!!!

Sponsor our Newsletter | Privacy Policy | Terms of Service