|
| |
|
|
lovduv
Posts: 152 Joined: 8/30/2005 Status: offline
|
*solved* Custom errors and duplicates - 2/20/2007 2:30:52
I am trying to have a custom error if a uaer puts in a duplicate name. My database is set and no duplicates are inserted. Now I need the custom error.... after some searching I saw a reply by spooky directing me here http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=106 and I am trying to use the last code: <%
' I assume you have a connection open...
objConn.Errors.Clear ' just to be safe, clear out any existing errors
On Error Resume Next ' then IGNORE errors!
catConn.Execute("INSERT INTO whateverTable (field1,field2,field3) Values(777,'whatever','and more')")
On Error GoTo 0 ' turn off the ignoring of errors!
' now see if we got any errors from the insert!
For Each oops In catConn.Errors
If oops.number = -2147217900 Then
Response.Write "That item already exists in that table!<BR>"
Else
Response.Write "Unexpected error: " & oops.number & " -- " & oops.description
End If
Next
%>
But I am using front page web bots to submit to DB with a simple form and I am not sure where to put this code?
< Message edited by lovduv -- 2/20/2007 18:31:08 >
|
|
|
|
BeTheBall
Posts: 6381 Joined: 6/21/2002 From: West Point Utah USA Status: offline
|
RE: Custom errors and duplicates - 2/20/2007 8:46:53
I think you will find this a better solution for your needs: http://www.spiderwebwoman.com/thingumajig/tweaks.htm#customerr
_____________________________
Duane Some people are like Slinkies . . . Not really good for anything . . . . . But they still bring a smile to your face when you push them down a flight of stairs.
|
|
|
|
lovduv
Posts: 152 Joined: 8/30/2005 Status: offline
|
RE: Custom errors and duplicates - 2/20/2007 13:10:50
Ok I moved it from here: End Select End If Response.End End If To here: End If Response.End End Select End If Now I have no error, but it still goes to my confirmation page? However in my DB I changed the indexed to (yes, no duplicates) so it does not add the duplicate record, but it does not let the user know that their input failed for trying to put in a duplicate, as it goes to my confirmation page? Do I need someting in the form?
< Message edited by lovduv -- 2/20/2007 15:54:27 >
|
|
|
|
lovduv
Posts: 152 Joined: 8/30/2005 Status: offline
|
RE: Custom errors and duplicates - 2/20/2007 16:27:52
Unfortunetly that didn't work anyone else This is the code for the form page:
<%
On Error Resume Next
Session("FP_OldCodePage") = Session.CodePage
Session("FP_OldLCID") = Session.LCID
Session.CodePage = 65001
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("stuff_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) = "nickname"
arFormDBFields0(0) = "nickname"
arFormValues0(0) = Request("nickname")
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"
fp_rs.Update
FP_DumpError strErrorUrl, "Cannot update the database"
fp_rs.Close
fp_conn.Close
Session("FP_SavedFields")=arFormFields0
Session("FP_SavedValues")=arFormValues0
Session.CodePage = Session("FP_OldCodePage")
Session.LCID = Session("FP_OldLCID")
Response.Redirect "gbthanks.asp"
End If
End If
Session.CodePage = Session("FP_OldCodePage")
Session.LCID = Session("FP_OldLCID")
%>
This is my form:
<form method="post" action="--WEBBOT-SELF--">
<!--webbot bot="SaveDatabase" SuggestedExt="asp" S-DataConnection="nickname" S-RecordSource="Results" U-Database-URL="xxxxxx" U-Confirmation-Url="thanks.asp" S-Builtin-Fields="REMOTE_HOST HTTP_USER_AGENT Timestamp" S-Builtin-DBFields="Remote_computer_name Browser_type Timestamp" S-Form-Fields="nickname" S-Form-DBFields="nickname" U-ASP-Include-Url="_fpclass/fpdbform.inc" startspan --><input TYPE="hidden" NAME="VTI-GROUP" VALUE="0"><!--#include file="_fpclass/fpdbform.inc"--><!--webbot bot="SaveDatabase" i-checksum="40548" endspan -->
<input name="gamertag" type="text" style="border: .2em #C0C0C0 inset; padding: .3em; width: 194px" /><br/>
<input name="Submit" type="image" src="Images/submitbutt.jpg" alt="Submit" value="submit"/>
</form>
|
|
|
|
lovduv
Posts: 152 Joined: 8/30/2005 Status: offline
|
RE: Custom errors and duplicates - 2/20/2007 18:17:07
Duhhhh I have redone this page so many times I forgot to put it on a diet------- Ok gonna go mess with the error code now that it will save!
|
|
|
|
lovduv
Posts: 152 Joined: 8/30/2005 Status: offline
|
RE: Custom errors and duplicates - 2/20/2007 18:26:36
All right all right..... Thank you Sally!!!!
|
|
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
|
|
|