Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
12-08-2010, 08:02 PM #1
- Join Date
- Dec 2010
- Thanked 0 Times in 0 Posts
Writing Array of Classes to DB Without Using Session
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, 10:50 PM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,650 Times in 2,619 Posts
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.PHP Code:
header('HTTP/1.1 420 Enhance Your Calm');