Holistic PHP + mySQL Question

Hi folks,

I’m seeking “approach advice” here.

I am uncertain the possible overall solution paths I can take to achieve the following. Would someone be willing to offer some suggestions, please? I would greatly appreciate it.

I have created a multi-step form that asks for a person’s details. At the end of the form, I have the option to Add Another Person. I would prefer to store the first person’s details in a session and move on to the next person until the user has completed adding people. In addition to the details, I will keep a running tally of people on-screen (via a session variable). When the user is finished, he/she would click a Complete button and all of the information would be saved to a database.

I have created the form. I am currently in the stage of solving the Add Person task.

How do I save multiple users (which are arrays, I presume) into a session? In oldschool languages (my experience with Pascal, C as well as a few modern ones) leads me down the path of thinking of multi-dimensional arrays. For example, customer[1,1] would be the first customer’s first name where customer[1,2] would be the first customer’s second name. Do these constructs exist for session variables? What are they called? And how do they work? Would this be the best path to take here? Or should I be thinking about this another way?

Thanks in advance for getting a dusty programmer dusted off. :slight_smile:

It’s late over here, and I’m tired and prone to mistakes, so I won’t give any coding advice right now, even though I might come back about that.

However, I do want to say that I think storing multiple multiple-step forms in a session, without keeping them somewhere safer seems a bit dangerous to me. What if the user has filled in ten people, and then mistakenly closes her browser window?

Even if you don’t wish to put the input into the regular database table/s until the user presses the final OK button, I think you should consider storing it in some kind of intermediate table, and building a function to recover a session if the connection was somehow lost. Remember, treat your users input as sacred :slight_smile:

This recent thread maybe helpful. :slight_smile:

+1 for adrian, save every input done even if it’s multidimensional array, just use serialize() before saving it to database and flag the temporary data as “draft”…

when the user suddenly closes the browser or what ever reason that halted the last encoding on the form, just check within the DB if userx has previous “draft” entry when he/she logins again, then pre-filled the form and just unserialize() the data from DB.