Jump to content

One Form for INSERTs and UPDATEs


doubledee

Recommended Posts

Is it possible - and reasonable - to have one Form which allows Users to create a new record (i.e. do an INSERT) and which also allows Users to modify an existing record (i.e. do an UPDATE)?  :confused:

 

When a User registers at my website, not only do they create a record in the "member" table, but one of the required fields is "First Name". 

 

What that means is that when I allow Users to edit details in their Profile - most of which were not included in registration to streamline the process - I don't have to worry about doing an INSERT, because I already created a "member" record and on the "Edit Details" page the first field is "First Name" so that is a hook so to speak where they can enter more info about themselves like...

- Location
- Date of Birth
- Interests
- Bio

 

and so on...

 

 

So here is my problem which I just discovered...

 

Also in my User Profile, I allow Users to answer several open-ended questions like...

1.) Why did you decide to start your own business?

2.) What advice would you share with others on what NOT to do? 

 

The problem is that these questions exist in the "bio_question" table and the answers that I am trying to get from Users will be stored in the "bio_answer" table but no record currently exists?!

 

So do I need both an "INSERT Answers Form" *and* an "UPDATE Answers Form", or can I combine things into one form?!

 

Hope that all makes sense?!

 

 

Debbie

Link to comment
Share on other sites

It makes sense.

You're saying you have 3 tables in total, the users table which stores registered users data. You have bio_questions table which I'm assuming is a list of questions that can be added/removed and they'll automatically appear in the users profile page for viewing or modifying.  You are then storing those answers in a separate table, 'bio_answers' which will have the users id and the answer to the question so we can properly determine which questions have been answered.

 

Now, if you are using the above method you will need to insert new data into bio_answers, you'll need to users id, the bio_questions id and the value. That way you can determine what questions have been answered, if no record exists then the question has not been answered.

 

So you will need to update the user data table for the info such as birthday, gender, etc. And for the bio_answers you will need to do a update if there is not a record, if there is a record you will update that table with new values.  So you will need to update the users table, and then either update or insert into the bio_answers table.

 

You can combine all this into one form, but you'll need to create the code to handle what data goes where.

 

A better method would be to add a field in the users table called bio_answers and store a serialized array of the data. That way you can just update the users table and have everything in once place. Of course your method is fine it'll just need some extra attention.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.