|
| |
|
|
hessfirm
Posts: 153 Joined: 9/15/2004 Status: offline
|
Getting the ID of last added record - 2/3/2006 13:30:22
Hi Spooky, or other experts... I read the post by Spooky about Getting the ID of last added record. At the end of the post, you mention a redirect after the form has been submitted. here is your post... If you are redirecting to another page, then the method is similar, however you will change the redirect code from this : Response.Redirect "confirmation.asp To this : Response.Redirect "confirmation.asp?ID="& NewId Then, in your 'confirmation' page the variable will be available via the request : <%=Request.Querystring("ID")%> I would like to auto redirect someone after they submit the form and pull over their unique ID as you suggest...just can't figure out where to put the redirect string. Below is the code after following your directions(works great)...where do i put the auto redirect script? <% On Error Resume Next Session("FP_OldCodePage") = Session.CodePage Session("FP_OldLCID") = Session.LCID Session.CodePage = 1252 Err.Clear strErrorUrl = "" If Request.ServerVariables("REQUEST_METHOD") = "POST" Then If Request.Form("VTI-GROUP") = "0" Then Err.Clear Set fp_conn = Server.CreateObject("ADODB.Connection") FP_DumpError strErrorUrl, "Cannot create connection" Set fp_rs = Server.CreateObject("ADODB.Recordset") FP_DumpError strErrorUrl, "Cannot create record set" fp_conn.Open Application("new_page_1_ConnectionString") FP_DumpError strErrorUrl, "Cannot open database" fp_rs.Open "Results", fp_conn, 1, 3, 2 ' adOpenKeySet, adLockOptimistic, adCmdTable FP_DumpError strErrorUrl, "Cannot open record set" fp_rs.AddNew FP_DumpError strErrorUrl, "Cannot add new record set to the database" Dim arFormFields0(1) Dim arFormDBFields0(1) Dim arFormValues0(1) arFormFields0(0) = "T1" arFormDBFields0(0) = "T1" arFormValues0(0) = Request("T1") FP_SaveFormFields fp_rs, arFormFields0, arFormDBFields0 If Request.ServerVariables("REMOTE_HOST") <> "" Then FP_SaveFieldToDB fp_rs, Request.ServerVariables("REMOTE_HOST"), "Remote_computer_name" End If If Request.ServerVariables("HTTP_USER_AGENT") <> "" Then FP_SaveFieldToDB fp_rs, Request.ServerVariables("HTTP_USER_AGENT"), "Browser_type" End If FP_SaveFieldToDB fp_rs, Now, "Timestamp" If Request.ServerVariables("REMOTE_USER") <> "" Then FP_SaveFieldToDB fp_rs, Request.ServerVariables("REMOTE_USER"), "User_name" End If fp_rs.Update NewId = fp_rs(0) FP_DumpError strErrorUrl, "Cannot update the database" fp_rs.Close fp_conn.Close FP_FormConfirmation "text/html; charset=windows-1252",_ "Form Confirmation",_ "Record ID "&NewId&" - Thank you for submitting the following information:",_ "captureuniqueid.asp",_ "Return to the form." End If End If Session.CodePage = Session("FP_OldCodePage") Session.LCID = Session("FP_OldLCID") %> <html> <head> <meta name="GENERATOR" content="Microsoft FrontPage 5.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>New Page 1</title> </head> <body> <form method="POST" action="--WEBBOT-SELF--"> <input TYPE="hidden" NAME="VTI-GROUP" VALUE="0"><!--#include file="_fpclass/fpdbform.inc"--><p> <input type="text" name="T1" size="20"><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p> </form> </body> </html>
_____________________________
Steve Hess
|
|
|
|
rdouglass
Posts: 9280 From: Biddeford, ME USA Status: offline
|
RE: Getting the ID of last added record - 2/3/2006 13:41:21
quote:
... "captureuniqueid.asp",_ "Return to the form." End If End If ... If you don't care about showing the confirmation, I'd suggest right in the middle there: ... "captureuniqueid.asp",_ "Return to the form." Response.Redirect("confirmation.asp?ID="& NewId) End If End If ...
_____________________________
Don't take you're eye off your final destination. ASP Checkbox Function Tutorial.
|
|
|
|
hessfirm
Posts: 153 Joined: 9/15/2004 Status: offline
|
RE: Getting the ID of last added record - 2/3/2006 13:48:14
hmmm....it doesn't auto redirect...just stays on the captureuniqueid.asp page (code below) and can you do without showing the id? i'll take either tecnhique. thanks! FP_FormConfirmation "text/html; charset=windows-1252",_ "Form Confirmation",_ "Record ID "&NewId&" - Thank you for submitting the following information:",_ "captureuniqueid.asp",_ "Return to the form." Response.Redirect("confirmation.asp?ID="& NewId) End If End If
_____________________________
Steve Hess
|
|
|
|
rdouglass
Posts: 9280 From: Biddeford, ME USA Status: offline
|
RE: Getting the ID of last added record - 2/3/2006 13:55:44
quote:
information:",_ "captureuniqueid.asp",_ "Return to the form." Response.Redirect("confirmation.asp?ID="& NewId) End If End If SO you have this code currently? What happens if you end the script as in: ... "captureuniqueid.asp",_ "Return to the form." Response.end Response.Redirect("confirmation.asp?ID="& NewId) ... What happens now with it?
_____________________________
Don't take you're eye off your final destination. ASP Checkbox Function Tutorial.
|
|
|
|
hessfirm
Posts: 153 Joined: 9/15/2004 Status: offline
|
RE: Getting the ID of last added record - 2/3/2006 14:02:16
darn...still stays on the captureunuiqueid.asp page...here is my code again: <% On Error Resume Next Session("FP_OldCodePage") = Session.CodePage Session("FP_OldLCID") = Session.LCID Session.CodePage = 1252 Err.Clear strErrorUrl = "" If Request.ServerVariables("REQUEST_METHOD") = "POST" Then If Request.Form("VTI-GROUP") = "0" Then Err.Clear Set fp_conn = Server.CreateObject("ADODB.Connection") FP_DumpError strErrorUrl, "Cannot create connection" Set fp_rs = Server.CreateObject("ADODB.Recordset") FP_DumpError strErrorUrl, "Cannot create record set" fp_conn.Open Application("new_page_1_ConnectionString") FP_DumpError strErrorUrl, "Cannot open database" fp_rs.Open "Results", fp_conn, 1, 3, 2 ' adOpenKeySet, adLockOptimistic, adCmdTable FP_DumpError strErrorUrl, "Cannot open record set" fp_rs.AddNew FP_DumpError strErrorUrl, "Cannot add new record set to the database" Dim arFormFields0(1) Dim arFormDBFields0(1) Dim arFormValues0(1) arFormFields0(0) = "T1" arFormDBFields0(0) = "T1" arFormValues0(0) = Request("T1") FP_SaveFormFields fp_rs, arFormFields0, arFormDBFields0 If Request.ServerVariables("REMOTE_HOST") <> "" Then FP_SaveFieldToDB fp_rs, Request.ServerVariables("REMOTE_HOST"), "Remote_computer_name" End If If Request.ServerVariables("HTTP_USER_AGENT") <> "" Then FP_SaveFieldToDB fp_rs, Request.ServerVariables("HTTP_USER_AGENT"), "Browser_type" End If FP_SaveFieldToDB fp_rs, Now, "Timestamp" If Request.ServerVariables("REMOTE_USER") <> "" Then FP_SaveFieldToDB fp_rs, Request.ServerVariables("REMOTE_USER"), "User_name" End If fp_rs.Update NewId = fp_rs(0) FP_DumpError strErrorUrl, "Cannot update the database" fp_rs.Close fp_conn.Close FP_FormConfirmation "text/html; charset=windows-1252",_ "Form Confirmation",_ "Record ID "&NewId&" - Thank you for submitting the following information:",_ "captureuniqueid.asp",_ "Return to the form." Response.end Response.Redirect("confirmation.asp?ID="& NewId) End If End If Session.CodePage = Session("FP_OldCodePage") Session.LCID = Session("FP_OldLCID") %> <html> <head> <meta name="GENERATOR" content="Microsoft FrontPage 5.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>New Page 1</title> </head> <body> <form method="POST" action="--WEBBOT-SELF--"> <input TYPE="hidden" NAME="VTI-GROUP" VALUE="0"><!--#include file="_fpclass/fpdbform.inc"--><p> <input type="text" name="T1" size="20"><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p> </form> </body> </html>
_____________________________
Steve Hess
|
|
|
|
rdouglass
Posts: 9280 From: Biddeford, ME USA Status: offline
|
RE: Getting the ID of last added record - 2/3/2006 14:36:23
quote:
Response.end Response.Redirect("confirmation.asp?ID="& NewId) End If Yes, that would cause it to stay there - the "response.end". I wasn't trying for a fix, just trying to see what showed up at that point. What happens with this: "Return to the form." Response.write("<br>NewID = " & NewID) Response.end Response.Redirect("confirmation.asp?ID="& NewId) Is anything written for NewID?
_____________________________
Don't take you're eye off your final destination. ASP Checkbox Function Tutorial.
|
|
|
|
hessfirm
Posts: 153 Joined: 9/15/2004 Status: offline
|
RE: Getting the ID of last added record - 2/3/2006 15:25:25
yes...what shows up now is: NewID = 16
_____________________________
Steve Hess
|
|
|
|
rdouglass
Posts: 9280 From: Biddeford, ME USA Status: offline
|
RE: Getting the ID of last added record - 2/3/2006 15:31:26
quote:
"Return to the form." Response.write("<br>NewID = " & NewID) Response.end Response.Redirect("confirmation.asp?ID="& NewId) SO now if you make that section like so: ... "Return to the form." Response.Redirect("confirmation.asp?ID="& NewId) ... (I just removed 2 lines, you can comment them out if you want to keep them for troubleshooting) If you make that section like so, you're saying it doesn't redirect anywhere?
_____________________________
Don't take you're eye off your final destination. ASP Checkbox Function Tutorial.
|
|
|
|
hessfirm
Posts: 153 Joined: 9/15/2004 Status: offline
|
RE: Getting the ID of last added record - 2/3/2006 15:40:53
now it works...great! do you think there is there a way to avoid showing the id in the string?
_____________________________
Steve Hess
|
|
|
|
rdouglass
Posts: 9280 From: Biddeford, ME USA Status: offline
|
RE: Getting the ID of last added record - 2/3/2006 15:51:09
quote:
do you think there is there a way to avoid showing the id in the string? Set a cookie? Set a session? Return it back in a form? There are 3 ways I can think of.
_____________________________
Don't take you're eye off your final destination. ASP Checkbox Function Tutorial.
|
|
|
|
hessfirm
Posts: 153 Joined: 9/15/2004 Status: offline
|
RE: Getting the ID of last added record - 2/3/2006 16:02:08
i will try to create a form, in place of the response.redirect, with an auto submit...does this sound doable?
_____________________________
Steve Hess
|
|
|
|
rdouglass
Posts: 9280 From: Biddeford, ME USA Status: offline
|
RE: Getting the ID of last added record - 2/3/2006 16:15:25
quote:
i will try to create a form, in place of the response.redirect, with an auto submit...does this sound doable? Definitely. I do it with a JavaScript. Something like so: <FORM name="returnForm" METHOD=POST ACTION="<%=Request.servervariables("HTTP_REFERER")%>" style="display:none"> <INPUT TYPE="text" NAME="NewID" value="<%=NewID%>"> <INPUT TYPE="submit"> </FORM> <script language="javascript"> document.forms["returnForm"].submit(); </script> That chunk would grab the NewID from that variable and send you back to the page it came from with the NewID in a form field. You could change the action to any page you choose. That help any?
_____________________________
Don't take you're eye off your final destination. ASP Checkbox Function Tutorial.
|
|
|
|
hessfirm
Posts: 153 Joined: 9/15/2004 Status: offline
|
RE: Getting the ID of last added record - 2/3/2006 16:36:38
getting closer...it doesn't seem to like that code when placed in the area we were working on...what i did was place it in the code below: FP_FormConfirmation "text/html; charset=windows-1252",_ "Form Confirmation",_ "Record ID "&NewId&" - Thank you for submitting the following information:",_ "Return to the form." <FORM name="returnForm" METHOD=POST ACTION="<%=Request.servervariables("HTTP_REFERER")%>" style="display:none"> <INPUT TYPE="text" NAME="NewID" value="<%=NewID%>"> <INPUT TYPE="submit"> </FORM> <script language="javascript"> document.forms["returnForm"].submit(); </script> End If End If I am guessing, though, that you weren't suggesting to put it where i did. what i am trying to do is have it auto submit in a form to another page so the id is hidden after the original id is created. did that make sense?
_____________________________
Steve Hess
|
|
|
|
hessfirm
Posts: 153 Joined: 9/15/2004 Status: offline
|
RE: Getting the ID of last added record - 2/4/2006 0:55:32
as always guys...excellent advice...here is my final code: page with entry form: FP_FormConfirmation "text/html; charset=windows-1252",_ "Form Confirmation",_ "Record ID "&NewId&" - Thank you for submitting the following information:",_ "Return to the form." Session("NewID") = NewID Response.Redirect("captureuniqueid_confirmation.asp") confirmation page: <body> Welcome <%Response.Write(Session("NewId"))%> </body>
_____________________________
Steve Hess
|
|
|
|
hessfirm
Posts: 153 Joined: 9/15/2004 Status: offline
|
RE: Getting the ID of last added record - 2/6/2006 10:56:08
Another question with this great concept... i am trying to switch the connection to our SQL DB I imported the table that was originally created using this technique from the fbdb directory on the site to our SQL table...then changed the connection string in the code below to match that of our global.asa. but when trying to write the NewId session variable, it now shows nothing. ](even though it is successfully writing the new record to the DB in SQL) below is the code that used to work...the bold is the only thing i changed...can i not use a sql connection in this method? <% On Error Resume Next Session("FP_OldCodePage") = Session.CodePage Session("FP_OldLCID") = Session.LCID Session.CodePage = 1252 Err.Clear strErrorUrl = "" If Request.ServerVariables("REQUEST_METHOD") = "POST" Then If Request.Form("VTI-GROUP") = "0" Then Err.Clear Set fp_conn = Server.CreateObject("ADODB.Connection") FP_DumpError strErrorUrl, "Cannot create connection" Set fp_rs = Server.CreateObject("ADODB.Recordset") FP_DumpError strErrorUrl, "Cannot create record set" fp_conn.Open Application("ANHDDedServer_ConnectionString") FP_DumpError strErrorUrl, "Cannot open database" fp_rs.Open "Results", fp_conn, 1, 3, 2 ' adOpenKeySet, adLockOptimistic, adCmdTable FP_DumpError strErrorUrl, "Cannot open record set" fp_rs.AddNew FP_DumpError strErrorUrl, "Cannot add new record set to the database" Dim arFormFields0(1) Dim arFormDBFields0(1) Dim arFormValues0(1) arFormFields0(0) = "T1" arFormDBFields0(0) = "T1" arFormValues0(0) = Request("T1") FP_SaveFormFields fp_rs, arFormFields0, arFormDBFields0 If Request.ServerVariables("REMOTE_HOST") <> "" Then FP_SaveFieldToDB fp_rs, Request.ServerVariables("REMOTE_HOST"), "Remote_computer_name" End If If Request.ServerVariables("HTTP_USER_AGENT") <> "" Then FP_SaveFieldToDB fp_rs, Request.ServerVariables("HTTP_USER_AGENT"), "Browser_type" End If FP_SaveFieldToDB fp_rs, Now, "Timestamp" If Request.ServerVariables("REMOTE_USER") <> "" Then FP_SaveFieldToDB fp_rs, Request.ServerVariables("REMOTE_USER"), "User_name" End If fp_rs.Update NewId = fp_rs(0) FP_DumpError strErrorUrl, "Cannot update the database" fp_rs.Close fp_conn.Close FP_FormConfirmation "text/html; charset=windows-1252",_ "Form Confirmation",_ "Record ID "&NewId&" - Thank you for submitting the following information:",_ "Return to the form." Session("NewID") = NewID Response.Redirect("captureuniqueid_confirmation.asp") End If End If Session.CodePage = Session("FP_OldCodePage") Session.LCID = Session("FP_OldLCID") %>quote:
Another question with this great concept... i am trying to switch the connection to our SQL DB I copied the table that was originally created using this technique from the fbdb directory on the site to our SQL table...then changed the connection string in the code below to match that of our global.asa. but when trying to write the NewId session variable, it shows nothing. (even though it is successfully writing the new record to the DB in SQL) below is the code that used to work...the bold is the only thing i changed...can i not use a sql connection in this method? <% On Error Resume Next Session("FP_OldCodePage") = Session.CodePage Session("FP_OldLCID") = Session.LCID Session.CodePage = 1252 Err.Clear strErrorUrl = "" If Request.ServerVariables("REQUEST_METHOD") = "POST" Then If Request.Form("VTI-GROUP") = "0" Then Err.Clear Set fp_conn = Server.CreateObject("ADODB.Connection") FP_DumpError strErrorUrl, "Cannot create connection" Set fp_rs = Server.CreateObject("ADODB.Recordset") FP_DumpError strErrorUrl, "Cannot create record set" fp_conn.Open Application("ANHDDedServer_ConnectionString") FP_DumpError strErrorUrl, "Cannot open database" fp_rs.Open "Results", fp_conn, 1, 3, 2 ' adOpenKeySet, adLockOptimistic, adCmdTable FP_DumpError strErrorUrl, "Cannot open record set" fp_rs.AddNew FP_DumpError strErrorUrl, "Cannot add new record set to the database" Dim arFormFields0(1) Dim arFormDBFields0(1) Dim arFormValues0(1) arFormFields0(0) = "T1" arFormDBFields0(0) = "T1" arFormValues0(0) = Request("T1") FP_SaveFormFields fp_rs, arFormFields0, arFormDBFields0 If Request.ServerVariables("REMOTE_HOST") <> "" Then FP_SaveFieldToDB fp_rs, Request.ServerVariables("REMOTE_HOST"), "Remote_computer_name" End If If Request.ServerVariables("HTTP_USER_AGENT") <> "" Then FP_SaveFieldToDB fp_rs, Request.ServerVariables("HTTP_USER_AGENT"), "Browser_type" End If FP_SaveFieldToDB fp_rs, Now, "Timestamp" If Request.ServerVariables("REMOTE_USER") <> "" Then FP_SaveFieldToDB fp_rs, Request.ServerVariables("REMOTE_USER"), "User_name" End If fp_rs.Update NewId = fp_rs(0) FP_DumpError strErrorUrl, "Cannot update the database" fp_rs.Close fp_conn.Close FP_FormConfirmation "text/html; charset=windows-1252",_ "Form Confirmation",_ "Record ID "&NewId&" - Thank you for submitting the following information:",_ "Return to the form." Session("NewID") = NewID Response.Redirect("captureuniqueid_confirmation.asp") End If End If Session.CodePage = Session("FP_OldCodePage") Session.LCID = Session("FP_OldLCID") %>
_____________________________
Steve Hess
|
|
|
|
hessfirm
Posts: 153 Joined: 9/15/2004 Status: offline
|
RE: Getting the ID of last added record - 2/6/2006 12:14:01
yes...i just imported the table from the fbdb directory...so everything appears to be the same.
_____________________________
Steve Hess
|
|
|
|
hessfirm
Posts: 153 Joined: 9/15/2004 Status: offline
|
RE: Getting the ID of last added record - 2/6/2006 15:37:31
just figured it out...thanks for your help...what needed to happen in the SQL table is that, even though it was an INT, i had to turn the ID into a primary key...don't ask me why. but it worked.
_____________________________
Steve Hess
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|