Såhär ser min sql-sträng ut: Gör en response.write(strSQL) Körde response.write(strSQL) istället för objConn.Execute(strSQL) men inte sa det mig så mycket (som jag fattade i alla fall).Problem med sista delen i sql-sträng. [LÖST]
strSQL = "INSERT INTO mails SET Receiver_ID = '"&arrReplyTo(I)&"', Sender_ID = '"&Session("id")&"', Status = '"&Session("Mail_NewMail_Status") &"', Sendt_Date_Time = '"&FormatDateTime(Date(), 0) & " " & FormatDateTime(Time(), 3)&"', Folder = 1, Subject = '"&Session("Mail_NewMail_Subject")&"', meddelande = '"&Session("Mail_OrginalMessage")&"', Subject = '"&Session("Mail_NewMail_Subject")
Det är något fel med det som kommer efter sista ",". Har jag inte avslutat rätt eller? Har testat att flytta så att tillexempel meddelande är sist istället för Subjekt men då blir det fel med meddelande.Sv: Problem med sista delen i sql-sträng. Behöver snabbt sva
så ser ofta väldigt lätt vad som är fel.Sv: Problem med sista delen i sql-sträng. Behöver snabbt sva
Här är nu hela sidans kod:
<%
Dim strReplyTo
Dim arrReplyTo
Dim I
' #### BEGIN ## Find selected users and check if they have the current user on the blocked list ####
Accepted_Users=""
Blocked_Users=""
Set rs = Server.CreateObject("ADODB.RecordSet")
SQL_Str="SELECT id, Blocked_Users FROM medlemmar WHERE id IN ("&Session("Mail_NewMail_Namelist")&") ORDER BY Username"
strDSN = "databasen"
rs.Open SQL_Str, strDSN
If Not rs.EOF Then
alldata=rs.getrows
rs.close
Set rs=nothing
numcols=ubound(alldata,1)
numrows=ubound(alldata,2)
For rowcounter=0 TO numrows
Str_User_ID=alldata(0,rowcounter)
Str_Blocked_Users=","&alldata(1,rowcounter)&","
If InStr(Str_Blocked_Users,","&Str_User_ID&",")<>0 Then
Blocked_Users=Blocked_Users&Str_User_ID&","
else
Accepted_Users=Accepted_Users&Str_User_ID&","
end if
Next
else
rs.close
Set rs=nothing
end if
If Not Accepted_Users="" Then Accepted_Users=Left(Accepted_Users,Len(Accepted_Users)-1) end if
If Not Blocked_Users="" Then Blocked_Users=Left(Blocked_Users,Len(Blocked_Users)-1) end if
' #### BEGIN ## Find selected users and check if they have the current user on the blocked list ####
' #### BEGIN ## Send mail to those users who doesn't have current user on blocked list ####
If Not Accepted_Users="" Then
arrReplyTo = Split(Accepted_Users, ",", -1, 1)
For I = LBound(arrReplyTo) To UBound(arrReplyTo)
Dim objConn
Dim strSQL
Dim rs
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "databasen"
strSQL = "INSERT INTO mails SET Receiver_ID = '"&arrReplyTo(I)&"', Sender_ID = '"&Session("id")&"', Status = '"&Session("Mail_NewMail_Status") &"', Sendt_Date_Time = '"&FormatDateTime(Date(), 0) & " " & FormatDateTime(Time(), 3)&"', Folder = 1, Subject = '"&Session("Mail_NewMail_Subject")&"', Subject = '"&Session("Mail_NewMail_Subject") &"', meddelande = '"&Session("Mail_OrginalMessage")& "'"
objConn.Execute(strSQL)
Set rs = Nothing
objConn.Close
Set objConn = Nothing
Next
end if
' #### BEGIN ## Send mail to those users who doesn't have current user on blocked list ####
Session("Mail_NewMail_Subject")=""
Session("Mail_NewMail_Status")=""
Session("Mail_OrginalMessage")=""
Response.Redirect "Mail_Mail_Sendt.asp?NotSentTo='" & Blocked_Users&"'"
%>
Kör jag koden så får jag detta felmeddelande nu:
Microsoft OLE DB Provider for ODBC Drivers fel '80004005'
[MySQL][ODBC 3.51 Driver][mysqld-3.23.52]Column 'Subject' specified twice
Byter jag till så att det istället står:
strSQL = "INSERT INTO mails SET Receiver_ID = '"&arrReplyTo(I)&"', Sender_ID = '"&Session("id")&"', Status = '"&Session("Mail_NewMail_Status") &"', Sendt_Date_Time = '"&FormatDateTime(Date(), 0) & " " & FormatDateTime(Time(), 3)&"', Folder = 1, Subject = '"&Session("Mail_NewMail_Subject")&"', Subject = '"&Session("Mail_NewMail_Subject")&"', meddelande = '"&Session("Mail_OrginalMessage")
...Så får jag detta felmeddelande:
Microsoft OLE DB Provider for ODBC Drivers fel '80040e09'
[MySQL][ODBC 3.51 Driver][mysqld-3.23.52]You have an error in your SQL syntax near ''detta är ett test' at line 1