|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Hi
For some reason the following SQL INSERT statement is adding two records and I can't work out why. It's a simple form with 3 dropdowns, created from database entries and another text field. The action returns to the same script, but filters based on content_length being <> 0 and goes to the following script: <% if request.ServerVariables("CONTENT_LENGTH")<>0 Then category=request.Form("category") provider=request.Form("provider") policynumber=request.Form("policynumber") lifeass=request.Form("lifeass") %> <!--#include file="connection.asp"--> <% strsql="INSERT INTO policies(visitorref,provider,policynumber,category ,lifeass)" strsql=strsql & "VALUES("&session.contents("visitorref")&",'"&provider&"','"&policynumber&"','"&category&"','"&lifeass&"')" conn.Execute(strsql) conn.close set rsgr=nothing set conn=nothing else %> .....Creates the form. The connection include just sets conn as ADODB connection and the database DSN. Can anyone shed any light on this problem? I can't see how it's calling this INSERT statement twice. Thanks |
|
#2
|
||||
|
||||
|
Do you have a submit button on the form?
Then just do this Code:
If Request.Form("SubmitButton") <> "" Then
Run your code
End If
|
|
#3
|
||||
|
||||
|
Yep. I'm using an image input type with a javascript onclick submit. Could this be the problem? This is the code for the whole form.
<table align="center" width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td valign="top" class="dbluetxt"><img src="addpolicy.gif" width="130" height="25" border="0"><br> <br> Select from the options below to add a policy for <font class="dorangetxtb"><%=session.Contents("forename1")%> <%=session.Contents("surname1")%></font> <% if session.Contents("visitor2ref")<>"" then response.Write(" and <font class=""dorangetxtb"">"&session.Contents("forename2")&" "&session.Contents("surname2")&"</font>")%> action=<%=action%></td> </tr> <tr> <td align="center"><br> <table width="550" border="0" cellpadding="0" cellspacing="0"> <tr> <td align="center" class="dorangetxtb">Category</td> <td> </td> <td align="center" class="dorangetxtb">Provider</td> <td> </td> <td align="center" nowrap class="dorangetxtb">Policy Number</td> <td> </td> <td align="center" class="dorangetxtb">Policy Owner</td> </tr> <tr> <td height="1" bgcolor="#000066" colspan="7"><img src="spacer.gif" width="1" height="1" hspace="0" vspace="0" border="0"></td> </tr> <!--#include file="connection.asp"--> <% response.Write("<form action=""mypolicies.asp?page=addpolicy"" method=""post"" name=""addpolicy""><tr><td>") response.Write("<select name=""category"" class=""registerform"">") response.Write("<option value="""">Please Select</option>") strsql="SELECT * FROM category" rsgr.open strsql,conn do until rsgr.eof response.Write("<option value="&rsgr("category")&">"&rsgr("category")&"</option>") rsgr.movenext loop response.Write("</select></td><td></td><td>") rsgr.close response.Write("<select name=""provider"" class=""registerform"">") response.Write("<option value="""">Please Select</option>") strsql="SELECT provider FROM providers ORDER BY provider ASC" rsgr.open strsql,conn do until rsgr.eof response.Write("<option value='"&rsgr("provider")&"'>"&rsgr("provider")&"</option>") rsgr.movenext loop response.Write("</select></td><td></td><td>") rsgr.close conn.close set rsgr=nothing set conn=nothing response.Write("<input type=""text"" size=""20"" name=""policynumber"" class=""registerform"">") response.Write("</td><td></td><td>") response.Write("<select name=""lifeass"" class=""registerform"">") response.Write("<option value="""">Please Select</option>") response.Write("<option value="&session.Contents("forename1")&">"&session.Contents("forename1")&"</option>") if session.Contents("visitor2ref")<>"" Then response.Write("<option value="&session.Contents("forename2")&">"&session.Contents("forename2")&"</option>") response.Write("<option value=""Joint"">Joint</option>") else end if response.Write("</select></td>") response.Write("<td width=""60"" align=""center"" class=""dbluetxtb""><input type=""image"" src=""add1.gif"" onclick=""this.form.submit()"" onMouseOut=""this.src='add1.gif'"" onMouseOver=""this.src='add2.gif'""></td></tr></form>") end if %> <tr> <td> </td> </tr> </table> </td> </tr> </table> |
|
#4
|
||||
|
||||
|
Check to make sure the submit image has been clicked, prior to executing the code to insert the new policy.
|
|
#5
|
||||
|
||||
|
Thanks for that.
Would you suggest adding a name and value to this <input> and then checking to see if the name=value before executing the SQL? Something like:- <input name=""add"" value=""add"" type=""image"" src=""add1.gif"" onclick=""this.form.submit()"" onMouseOut=""this.src='add1.gif'"" onMouseOver=""this.src='add2.gif'""> and then check: <% if request.form("add")="add" then %> execute SQL Insert script |
|
#6
|
||||
|
||||
|
Yes, that should work.
|
|
#7
|
||||
|
||||
|
Tested it with a normal submit button and it worked fine, so removed the OnClick event on the image input and it was this that was causing the double submission.
Didn't realise the image type would act as a submit button even without an OnClick event. ![]() |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > Doubling Insert |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|