Get ready for BLACK FRIDAY shopping starting in

Forums

This topic is locked

Problem inserting record into DB

Posted 05 Mar 2002 03:19:09
1
has voted
05 Mar 2002 03:19:09 Spencer Nash posted:
Hi,
I've got a page that I'm making with ASP to let teachers login and leave comments for their students. I've got one part of the form that is a yes/no question. If the user clicks yes, a new window is launched with another short form asking for missing assignments from the student. If the user inputs the information, goes back to the previous page and completes that form also, everything works fine.

The problems come up when the user clicks no to the question and goes about finishing to form. When they press submit, the DB is never updated.

The problem is that I've got the Insert Record Behavior on the second form that is opened. The behavior on the original page is an Update behavior. Obviously, you can't update a record that has never been inserted.

Is there any way I could make this work? All the data that is being inserted goes into one table because of the need to be able to delete all the information at once about a particular comment (long story). Is there any kind of "Update If...Otherwise Insert" kind of extension that anyone knows about? Or does anyone know of a way that I could make this work?

Thanks,
Spencer

Replies

Replied 05 Mar 2002 06:10:39
05 Mar 2002 06:10:39 Steven Tam replied:
In your form where you asked the Yes/No question. Add an "If-Then-Else If" to test the answer. Something like this...

<%if answer="yes" then %>
... open 2nd form ....
<% else %>
... insert record ...
<% end if %>




Replied 05 Mar 2002 06:32:31
05 Mar 2002 06:32:31 Spencer Nash replied:
The problem with that is that if I open the second form, I have to Insert that information before the first form. On the other hand, if the second form is not opened, I need a way to Insert instead of update, because right now there is only one table with all the information in it.
I probably will have to redesign the db, but I'm hoping that I won't have to.
Spencer

Replied 05 Mar 2002 06:43:01
05 Mar 2002 06:43:01 Steven Tam replied:
you can carry all your answers from the 2nd form back to the 1st form and insert all fields to the db from your 1st form.

Replied 05 Mar 2002 06:45:35
05 Mar 2002 06:45:35 Steven Tam replied:
continue from last reply...

that way, no matter the answer is yes or no, either the 2nd form is opened or not, you only do insert once for all the fields from the 1st form.

Replied 05 Mar 2002 07:09:41
05 Mar 2002 07:09:41 Spencer Nash replied:
Thanks psalm,
Could you explain a little more about how I could do this?
I'm guessing that I'll have to use hidden fields, but I'm not quite sure on the setup.

Thanks again,
Spencer

Replied 05 Mar 2002 08:02:29
05 Mar 2002 08:02:29 Steven Tam replied:
the easiest way is to setup some session variables.

in form 1

<%
session("variable_1"=""
session("variable_2"=""
session("variable_3"=""
...
%>
...
<form>
...
<input type=hidden name=variable_1 value="<%=session("variable_1"%>">
<input type=hidden name=variable_2 value="<%=session("variable_2"%>">
<input type=hidden name=variable_3 value="<%=session("variable_3"%>">
...
</form>

=====================================
in form 2. when user click on the submit button, you need to assign the values from the form to the session variables.



psalm









Reply to this topic