View Full Version : Writing Array of Classes to DB Without Using Session

12-08-2010, 09:02 PM
I am writing a form to insert a person's information to a database using a form and PHP. I am planning on storing each person's data using a "Person" class. However, I want the user to fill out the form multiple times and then submit an entire array of "Person" classes all at once. I have a couple questions:

1) To do this, should I still use a POST action to retrieve the inputs to populate each individual class or just obtain them through java script?

2) To update my array with a new Person class, would I have to store this array in the session, or is there another way?


12-08-2010, 11:50 PM
1. Javascript is for fun. Make sure it works without it first then make it awesome with JS. PHP can (and should be) usable without JS.

2. No other way. Well, cookies, but that's worse. This is a limitation of HTTP, you cannot persist your data between multiple calls without using alternate methods such as sessions. The ONLY way to do this without is to take an array and flatten with the serialize method and pass it through each form load. This is a huge waste, is now a potential threat, and makes extra work since you need to unserialize the data, add another item, and serialize it again.

Given the description though, I see no reason to accept multiple Person's and then update the database when you can update the database between each person being loaded. That can also be done with AJAX if you are using it to quicken the forms up.