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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AddNew() creates 2 entries

Status
Not open for further replies.

jeepxo

Programmer
Oct 1, 2002
228
CA
I'm really stumped by this now. I don't have any loops, I've commented out everything else so I know that I am looking at the only code that is running and it still happens.

When I create a new entry in the database, it creates 2 identicle entries.

It doesn't matter if I use AddNew() or if I use an Insert statement. You will see both in the code, I've commented out the AddNew() portion.



Code:
if (isblank(eid))
	{
		Response.Write(&quot;<br>eid is blank<br>&quot;)
		var rstEmployers = Server.CreateObject(&quot;ADODB.RecordSet&quot;);
		var rsContacts = Server.CreateObject(&quot;ADODB.RecordSet&quot;);
		seedFromPage();	
		var mySQLStatement = &quot;INSERT into Employer (Name, Address1, Address2, City, PostalCode, Region) &quot;
		mySQLStatement += &quot;VALUES ('&quot;+ employerName + &quot;','&quot; + address1 + &quot;','&quot; + address2 +&quot;','&quot; + city + &quot;','&quot;;
		mySQLStatement += postal + &quot;','&quot; +Session(&quot;region&quot;) + &quot;')&quot;;
		oConn.Execute(mySQLStatement);
		mySQLStatement = &quot;SELECT * from Employer where Name='&quot; +employerName +&quot;' and Region='&quot; + Session(&quot;region&quot;) + &quot;' order by employerID desc&quot;;
		rstEmployers.Open(mySQLStatement,oConn,adOpenStatic, adLockReadOnly)
		rstEmployers.MoveLast();
		eid = rstEmployers(&quot;employerID&quot;).Value;
		rstEmployers.Close();
		Response.Write(eid);
		/*rstEmployers.Open(&quot;employer&quot;, oConn, adOpenKeyset, adLockPessimistic)

		if ((rstEmployers.EOF)&&(rstEmployers.BOF))
		{
			Response.Write(&quot;There is nothing in the recordset&quot;);
		}
		rstEmployers.MoveLast();
		rstEmployers.Addnew();
		rstEmployers.Update();
		
		Response.Write(&quot;<br>eid = &quot; + rstEmployers(&quot;EmployerID&quot;).value)
		Response.Write(&quot;<br> now updating the content&quot;);
		rstEmployers.MoveLast();
		seedFromPage();
		rstEmployers(&quot;Name&quot;) = employerName;
		rstEmployers(&quot;Address1&quot;) = address1; 
		rstEmployers(&quot;Address2&quot;) = address2;
		rstEmployers(&quot;city&quot;) = city;
		rstEmployers(&quot;PostalCode&quot;) = postal;
		rstEmployers(&quot;region&quot;)= Session(&quot;region&quot;);
		Response.Write(&quot;<br>eid = &quot; + rstEmployers(&quot;EmployerID&quot;).value)
		rstEmployers.Update();
		eid = rstEmployers(&quot;EmployerID&quot;).Value;
		Response.Write(&quot;<br>eid = &quot; + rstEmployers(&quot;EmployerID&quot;).value)
		rstEmployers.Close();
		*/
		/*mySQL= &quot;insert into employer (Name, address1, region) values ('bah','bah','peterborough')&quot;
		
		rsEmployers(&quot;employerID&quot;) = oConn.Execute(mySQL);
		Response.Write(rsEmployers(&quot;employerID&quot;).Value);
		*/
		}

&quot;Every day is like a precious gift, you have to make it count&quot; James Birrell 1993-2001
 
The few times I have run into this in the past it was usually because the previous page was double submitting. Generally this would be something like having an onSubmit in the form tag but also using form.Submit() in the script that is being called. Example:
Code:
<script language=&quot;javascript&quot;>
function doStuff(){
   //do a bunch of validation stuff
   frmname.submit()
}
<!-- bunch of html stuff -->
<form method=POST action=&quot;otherpage.asp&quot; onSubmit=&quot;soStuff();&quot;>

This causes a double submission, but you only get to see the browser output on the second one, which makes it hard to detect.

Not saying this is the problem, as I don't know enough about your code, but it's a likely possibility,

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Good call on that one!

Thanks

&quot;Every day is like a precious gift, you have to make it count&quot; James Birrell 1993-2001
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top