tags:

views:

346

answers:

4

Forgive me as I am a newbie. I have a multi page form in which I am using $_SESSIONS to record the variables.

<?php
session_start();
foreach ( $_POST as $key=>$value ) {
    if ( $key!="submit" ) {
        $value= htmlentities(stripslashes(strip_tags($value)));
        $_SESSION[$key] = $value;
    }
}`

I have two problems actually. When I get to a checkform.php that I made that prints out the variables, The variables from page 1 doesn't show up even though that code listed above is on each page. I am using Firefox web developers tool to disable cookies and in the php ini, I altered session.use_trans_sid to 1 to turn it on. For the final page on my checkform.php I print_r($_POST) for the final page which works fine. Why doesn't variables from page 1 not show up? What am I missing?

The 2nd problem is that when I print_r($_SESSION), some fields, specifically the checkbox arrays, print as

[payment] => Array
[agerange] => Array
[meals] => Array
[mealtypes] => Array

What am I missing?

A: 

In your form tag, are you using "Get" or "Post" for your method? That's the only reason I can see that the $_POST array would be empty on page 1...

Jefe
A: 

I'm not sure about your first problem. You can consider passing the information using a POST tag to the second verification page.

I can give an answer to your second problem: it's only printing an array because you asked it to. You'll need to use a foreach() to echo each piece of the array.

There's no such thing as a stupid question.

Brandon Wang
A: 

Jefe I don't understand. I am using POST on every page. Why wouldn't the variables 'be set' ( I hope that is the proper terminology) . Should I exclude the if statement that asks if the submit button variable was set? Could I change it to if ($firstvariable="" then.

Brandon... Eventually I want to send these values to MySql. I am just echoing them out to see that they are there. Do I need to loop a foreach at the end of the form just before entering them into the database or should I include a foreach statement for each page that has a checkbox array?

A: 

i agree with Jefe

Asinox