close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

How to insert new id or return and insert a duplicate id

Thread begun 9/23/2013 11:59 am by jurinski334466 | Last modified 10/07/2013 8:03 am by Jason Byrnes | 5088 views | 17 replies |

jurinski334466

How to insert new id or return and insert a duplicate id

I have an insert form with two insert server record behaviors in it that uses two tables. Table 1 has a drop down menu showing existing selections and a text field to enter a new value. This field and form work when entering a new value and correctly shows an error when entering a duplicate value. But, how do I get the duplicate id to use to insert into table 2? How do I enter either an existing value or a new value?

I did not find anything in the WA forum or materials about how to do this, but I did find code on the internet using "if...else" around the insert statement; however, I was unsuccessful trying to adapt it to the WA code. I'm sorry, I don't know enough about what I'm doing to figure this out or whether there is a better way to accomplish what I'm trying to do so I'm hoping you can help me out and point me in the right direction. Thank you.

Sign in to reply to this post

Jason ByrnesWebAssist

send a copy of the page please.

Sign in to reply to this post

jurinski334466

Thank you for looking at this for me.

Sign in to reply to this post

jurinski334466

Please let me know if you need any additional files or information. Thanks!

Sign in to reply to this post

Jason ByrnesWebAssist

add the following code after the first insert and before the second one:

php:
<?php if((!isset($_POST["newTitle"]) || $_POST["newTitle"] == "") && (isset($_POST['CourseTitleID']) && $_POST['CourseTitleID'] != "")) $_SESSION['WADA_Insert_coursetitle'] = $_POST['CourseTitleID']; ?>
Sign in to reply to this post

jurinski334466

Thank you for getting back to me. Unfortunately, I couldn't get this code to work. I still get the error, " Duplicate entry 'A New Course' for key 'coursetitle' ". I tried placing the code between the two inserts (and several other places and hiding other bits of code as well), but no luck.

I was thinking that somehow code could be used to bypass the first insert if a duplicate were found and just return the id of the duplicate. (Similar to how the id of a new insert is returned?), and then use the id of the duplicate in the second insert? Does the error message mean the code is not getting past the first insert? I apologize for not understanding this better. Or maybe I just goofed something up...

I tried working with this code last weekend. I don't know if it could be helpful. I wasn't able to make it work. With my luck, it was probably meant to do something else entirely... :-)

Maybe I have the database or validation set up wrong?

I would appreciate if you could let me know what I am doing wrong and look at this again for me.
Thanks again!

Sign in to reply to this post

Jason ByrnesWebAssist

Edit the Course title insert behavior, for the trigger, select the New title form element so a new title will only be inserted if one is enterred

Sign in to reply to this post

jurinski334466

Thank you! Success! That worked! I couldn't be more appreciative. I'm impressed with how quick, helpful, and patient you've been. Thank you again!

Sign in to reply to this post

jurinski334466

I thought I was in the clear with the insert page working, but I'm having trouble with the update page now. I thought I could adapt the changes made to the insert page to the update page, but I have not had any success using two update server behaviors on one page to update two tables linked by the foreign key.

I tried making the page with a text field, a select list, both a text field and a select list, combining the code from the working coursetitle_update and the coursetitlesdescriptions_update page, but I'm not sure what approach I should take to set up the form, what needs renaming and where, and how to correctly pass the information between the two updates. The information in the forum hasn't contained enough detail for me to get a handle on what I'm doing wrong and how to fix it.

Could you please tell me what steps I need to take to update the parent table and then update the foreign key in the child table to update both tables? I attached a copy of my form. Please let me know if you need more information. Thank you!

Sign in to reply to this post

Jason ByrnesWebAssist

Use a select list for the existing course titles, use a recordset to populate the list. and a text box for new course title.

Use an insert record behavior to insert the new course title. For the trigger, click the lightning bolt icon, and select the New Course title text box. This will insert a new record if a new course title is entered, but skip the insert if new course title is left blank.

In the insert record behavior, set the save Inserted ID in Session option to a session named:
NewTitle

after the insert behavior, use the following code to set the CourseTitle form element to use the inserted ID if it exists:
<?php if((isset($_SESSION['NewTitle'])?$_SESSION['NewTitle']:"") != "") $_POST['CourseTitle'] = $_SESSION['NewTitle']; ?>

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...