Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Insert - Two Records Added with 1 Submit 1

Status
Not open for further replies.

Shelly

Programmer
Sep 8, 2000
17
US
I have an asp page that takes the values from a form and uses an insert into statement to add the record to an SQL database. I open the connection, set up the sqlstmt and then do: conn.execute(sqlstmt). It then writes a statment to the user that the record was added. Now here is the problem: most of the time the record is added twice; however, today we noticed that if the page was closed quickly, only one record is added. It is not a consistent problem. This is running on a new computer and Netscape. My thought was that maybe the page is reloading itself, therefore adding another record. Any help will be appreciated.

Shelly
 
Best advice.
Prior to the conn.execute(sqlstmt) line insert a
Response.write sqlstmt
response.end

This will allow you to see in plain text exactly what is being handed to the the database to execute. That's where you will be able to see what is getting passed, and should find your double records.


 
Did you tried to use a response.redirect after inserting?
A long time ago I also had a problem with Netscape, cause it loaded the page twice. After a redirection everything worked fine. But I still don't know why it was loaded twice. Your ASP-code looks fine to me.

Hope the redirection will help... good luck
 
I had this problem if a user pressed the submit button twice whilst waiting, or by mistake. Try adding this and see what happens.
I now use a submit once js function and a hidden form field like this anyway on all forms.

add:
onsubmit="submitonce(this)" in the form/button code

add:
<input type=&quot;hidden&quot; name=&quot;submitted&quot; value=&quot;No&quot;>

put your usual form onsubmit validation in a function called validate()

and add this function ! good luck

function SubmitOnce(theForm){

//Make sure the form sumit button only pressed once
//If not already submitted then call the validation and submit

if (theForm.submitted.value==&quot;Yes&quot;) {
alert('This form has already been submitted - press buttons only once and wait for a response. Do not use the browser back button');
return(false);
}
else{

//Not submitted so check the validation
if (Validate(theForm)!=false) {
theForm.submitted.value=&quot;Yes&quot;;
return(true);
}
else{
return(false);
}
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top