PDA

Click to See Complete Forum and Search --> : I gotta get your help on this!


jesus4u
Mar 30th, 2001, 11:28 AM
THis is driving me nutso!

I am entering 7 emails into a DB. First table has the senders' emails and the second tables has the recipients' emails.

After I enter the senders' email I then enter in the recipients' emails but on first try ,with a new sender, the recipient emails get entered in fine but if I have the same sender send to additional recipients the data gets replicated twice!!!!!!!!!

THe problem area seems to be the ssql2 statement where I am doing a loop to enter in all the emails from the form.

THis is done in .asp VBscript.

Again the question is WHY are my emails duplicated into the DB for the recipient table only?

Is it because I use the variable frmEmail more than once on the same page?

Sorry this is SOOOOO long!!!

Code is below to debug:

<!-- #INCLUDE FILE="validate.asp" -->
<!-- #INCLUDE FILE="data.asp" -->
<%
on error resume next

Dim strAns

strAns = "Please enter a valid e-mail"

If Request.Form("Y1") = "" Then
Session("Y1") = strAns
Response.Redirect "EmailFriend.asp"
End If

Dim MyEmail(5)
Dim frmEmail(5)
Dim SenderEmail
Dim chkOK
Dim Count, frmCount, frmCount2
Dim AllOK, objCDO, objCDO2, txtSubject, txtSubject2

SenderEmail = Request.form("Y1")
MyEmail(0) = Request.form("A1")
MyEmail(1) = Request.form("A2")
MyEmail(2) = Request.form("A3")
MyEmail(3) = Request.form("A4")
MyEmail(4) = Request.form("A5")
MyEmail(5) = Request.form("A6")
chkOK = Request.form("C1")
strOrigin = Request.ServerVariables("HTTP_REFERER")

For Count = 0 to 5
If chkEmail(MyEmail(Count)) = 1 Then
AllOK = AllOK + 1
End If
Next

If chkEmail(SenderEmail) = 1 Then
AllOK = 1
End If

If AllOk = 1 Then
Response.Redirect "error.asp"
End If

If chkOK <> "" Then
chkOK = True
Else
chkOK = False
End If

'--get email addresses

SenderEmail = Request.form("Y1")
frmEmail(0) = Request.form("A1")
frmEmail(1) = Request.form("A2")
frmEmail(2) = Request.form("A3")
frmEmail(3) = Request.form("A4")
frmEmail(4) = Request.form("A5")
frmEmail(5) = Request.form("A6")

'--Enter emails in DB

Dim Dconn, sSQL, sSQL2, cmDC, SQL, Recordset, lrecAff

Set Dconn = Server.CreateObject("ADODB.Connection")
Dconn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & _
databasepath & ";"

Set cmdDC = Server.CreateObject("ADODB.Command")
cmdDC.ActiveConnection = Dconn

SQL = "Select Sender.Email, Sender.AID FROM Sender WHERE " & "Sender.Email ='" & SenderEmail & "'"

cmdDC.CommandText = SQL
Set RecordSet = Server.CreateObject("ADODB.Recordset")

RecordSet.Open cmdDC, , 3, 3

If Recordset.EOF Then
sSQL = "INSERT into Sender(Email, OK2Remind, Origin)VALUES('" & SenderEmail & "','" & chkOK & "','" & strOrigin & "')"
Dconn.Execute sSQL
End If

'--Use a For Next loop to enter in the 6 emails from the form and the SenderAID field into the Recipient SenderID field.

For frmCount2 = 0 To 5
If frmEmail(frmCount2) <> "" Then
sSQL2 = "INSERT into Recipient(Email, SenderID)VALUES('" & frmEmail(frmCount2) & "'," & Recordset.fields("AID") & ")"
Dconn.BeginTrans
Dconn.Execute sSQL2, lrecAff
If lrecAff = 1 Then
Dconn.RollbackTrans
Else
Dconn.CommitTrans
End If
End If
Next

set cmdDC = nothing
Recordset.close
set recordset = nothing

Dconn.Close
Set Dconn = Nothing

'--sends email to Client, cc to host

For frmCount = 0 To 5

If frmEmail(frmCount) <> "" AND AllOk = 0 Then

Set objCDO = Server.CreateObject("CDO.Message")
objCDO.From = "a.polajenko@crministries.org"
objCDO.To = frmEmail(frmCount)
objCDO.bcc = "a.polajenko@crministries.org"

txtSubject = "recipient test"
objCDO.Subject = "Testing"
objCDO.TextBody = txtSubject
objCDO.Send
Set objCDO = nothing

'--sends confirmation email to sender

Set objCDO2 = Server.CreateObject("CDO.Message")
objCDO2.From = "a.polajenko@crministries.org"
objCDO2.To = SenderEmail
objCDO2.bcc = "a.polajenko@crministries.org"

txtSubject = "sender test"
objCDO2.Subject = "Testing"
objCDO2.TextBody = txtSubject
objCDO2.Send
Set objCDO2 = nothing
End If
Next


Response.Redirect "Form.asp"

%>