SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old September 13th, 2004, 09:49 AM
richyrich's Avatar
richyrich richyrich is offline
Contributing User
ASP Free Specialist (4000 - 4499 posts)
 
Join Date: Jun 2004
Location: Somewhere only we know...
Posts: 4,192 richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)  Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 1 Week 1 Day 19 h 4 m 48 sec
Reputation Power: 1209
Question Doubling Insert

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

Reply With Quote
  #2  
Old September 13th, 2004, 09:52 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
Do you have a submit button on the form?
Then just do this
Code:
If Request.Form("SubmitButton") <> "" Then
   Run your code
End If

Reply With Quote
  #3  
Old September 13th, 2004, 10:09 AM
richyrich's Avatar
richyrich richyrich is offline
Contributing User
ASP Free Specialist (4000 - 4499 posts)
 
Join Date: Jun 2004
Location: Somewhere only we know...
Posts: 4,192 richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)  Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 1 Week 1 Day 19 h 4 m 48 sec
Reputation Power: 1209
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")%>&nbsp;<%=session.Contents("surname1")%></font>
<% if session.Contents("visitor2ref")<>"" then response.Write("&nbsp;and&nbsp;<font class=""dorangetxtb"">"&session.Contents("forename2")&"&nbsp;"&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>&nbsp;</td>
<td align="center" class="dorangetxtb">Provider</td>
<td>&nbsp;</td>
<td align="center" nowrap class="dorangetxtb">Policy Number</td>
<td>&nbsp;</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>&nbsp; </td>
</tr>
</table>
</td>
</tr>
</table>

Reply With Quote
  #4  
Old September 13th, 2004, 10:14 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
Check to make sure the submit image has been clicked, prior to executing the code to insert the new policy.

Reply With Quote
  #5  
Old September 13th, 2004, 10:28 AM
richyrich's Avatar
richyrich richyrich is offline
Contributing User
ASP Free Specialist (4000 - 4499 posts)
 
Join Date: Jun 2004
Location: Somewhere only we know...
Posts: 4,192 richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)  Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 1 Week 1 Day 19 h 4 m 48 sec
Reputation Power: 1209
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

Reply With Quote
  #6  
Old September 13th, 2004, 10:35 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
Yes, that should work.

Reply With Quote
  #7  
Old September 14th, 2004, 05:53 AM
richyrich's Avatar
richyrich richyrich is offline
Contributing User
ASP Free Specialist (4000 - 4499 posts)
 
Join Date: Jun 2004
Location: Somewhere only we know...
Posts: 4,192 richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)richyrich User rank is General 4th Grade (Above 100000 Reputation Level)  Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1Folding Points: 126743 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 1 Week 1 Day 19 h 4 m 48 sec
Reputation Power: 1209
Smile Doubling Insert - Solved

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.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Doubling Insert


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT