View Full Version : INSERT vs. UPDATE while going back to double check...
06-21-2006, 02:59 AM
-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?
06-21-2006, 03:28 AM
Yeah, you're going to have to account for situtations like that.
06-21-2006, 11:54 AM
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?!
06-21-2006, 12:15 PM
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.
06-21-2006, 12:31 PM
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?
06-21-2006, 12:33 PM
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.
06-21-2006, 12:52 PM
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?
06-21-2006, 09:54 PM
To copy the fields posted by the previous page into the session you just use:
$_SESSION('fieldname') = $_POST('fieldname');
06-21-2006, 10:48 PM
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??
06-22-2006, 01:31 AM
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.
06-22-2006, 02:44 AM
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?
06-22-2006, 05:11 AM
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.
06-22-2006, 12:16 PM
Great... I'll try out the new code...I'll get back with the results.
Thanks for your help!!
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.