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 13 of 13
  1. #1
    Regular Coder
    Join Date
    Mar 2005
    Posts
    240
    Thanks
    1
    Thanked 0 Times in 0 Posts

    INSERT vs. UPDATE while going back to double check...

    Hi there

    -On page 1 of a registration form I have an INSERT quiery to input the data in the DB.
    -On page 2 I have an UPDATE for additional fields
    -On page 3 I also have an UPDATE statement for remaining fields

    On page 4 it's the confirm page to make sure the data is right for the user. It's basically a SELECT quiery

    My question is, if the user were to go back to page 1 and make some changes, would that basically create an issue since there is an "INSERT" quiery and not an "UPDATE" quiery?

    Because basically, once the user clicks on "next" to go to page 2, the user ID is already created and for those fields, the INSERT quiery inputs the data...

    Wouldn't a second INSERT create an additional user ID?

    thanks

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Yeah, you're going to have to account for situtations like that.

  • #3
    Regular Coder
    Join Date
    Mar 2005
    Posts
    240
    Thanks
    1
    Thanked 0 Times in 0 Posts
    What would be the best way to solve this issue?

    Is there a way that the info can be "held" right up until the confirmation page and then do one INSERT?!

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You could use $cookie or $session variables to accomplish that. Or, you could just carry a primary unique ID through each page and check to see if that ID exists before inserting.

  • #5
    Regular Coder
    Join Date
    Mar 2005
    Posts
    240
    Thanks
    1
    Thanked 0 Times in 0 Posts
    fumigator...so there wouldn't be an insert (or update) up untli the end of the registration process (page 4) and on page 4 there would be a submit?

    And I hold all that data through a SESSION up until the last page?

  • #6
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think that would be the best way, hold it in the session up until the last page... also, that way if someone doesn't complete registration you don't have a half-finished record left in the DB.

  • #7
    Regular Coder
    Join Date
    Mar 2005
    Posts
    240
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I've never done this before...

    I've done a session start at the beginning but what would be a sample script that would hold the data up until the last page?

    Thanks

  • #8
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,640
    Thanks
    0
    Thanked 649 Times in 639 Posts
    To copy the fields posted by the previous page into the session you just use:

    $_SESSION('fieldname') = $_POST('fieldname');
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #9
    Regular Coder
    Join Date
    Mar 2005
    Posts
    240
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Great thanks felgall... So I do that for all the fields which basically carries all the fields over until the last page (of 3 pages worth of registration information) and in the last page I create an insert?

    Do I need an insert script when I carry over the data in a SESSION in the first few pages??

  • #10
    Regular Coder
    Join Date
    Jan 2004
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts
    One thing you can do is a SELECT statement on the first page to see if the information is already there; if theres info in the database, just skip inserting the info.

  • #11
    Regular Coder
    Join Date
    Mar 2005
    Posts
    240
    Thanks
    1
    Thanked 0 Times in 0 Posts
    So generally speaking, when you do a $_SESSION('fieldname') = $_POST('fieldname'); to pass data in a session, on that page do you insert? Or do you wait until the final page to do the insert?

  • #12
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Generally speaking, you'd wait until the user has entered all of the data he needs to enter, and you have validated all of that data, and then insert the validated data into a database.

  • #13
    Regular Coder
    Join Date
    Mar 2005
    Posts
    240
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Great... I'll try out the new code...I'll get back with the results.

    Thanks for your help!!


  •  

    Posting Permissions

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