Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Writing Array of Classes to DB Without Using Session

    Hi,
    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?


    Thanks

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •