quando vado ad inserire dei dati (news) nel Db mi da quest'errore !
[Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
/news/admin/edit.asp, line 77
<%@LANGUAGE="VBSCRIPT"%>
<%
' verifica utente amministratore connesso...
if not session("adminLogged") then
response.redirect "login.asp"
end if
' verifichiamo se la pagina è stata chiamata passandole via FORM o queryString in valore ID
id = request("id")
' se l'ID c'è vuol dire che si tratta di una modifica...
if len(id) > 0 and IsNumeric(id) then
id = clng(id)
else
' ... altrimenti è un nuovo inserimento.
id = 0
end if
' connessione...
set conn = server.createObject("ADODB.Connection")
conn.open connString
' se la pagina è stata chiamata via FORM vorrà dire che si sta eseguendo una operazione di MODIFICA o un NUOVO INSERIMENTO...
if submit then
' prendiamo i dati...
ntitle = trim(request.form("title"))
ntitle = replace(ntitle,"'","''")
nbody = trim(request.form("body"))
nbody = replace(nbody,"'","''")
ndate = request.form("date")
nstatus = clng(request.form("stato"))
' controlliamo che i dati ci siano...
if len(ntitle) = 0 then
errore = true
messaggio = messaggio & "Il campo TITOLO è obbligatorio!
"
end if
if len(nbody) = 0 then
errore = true
messaggio = messaggio & "Il campo CORPO è obbligatorio!
"
end if
if len(ndate) = 0 then
ndate = FormatDateTime(Date(),vbGeneralDate)
else
if not isDate(ndate) then
errore = true
messaggio = messaggio & "Il campo DATA deve contenere una data valida!
"
else
ndate = cdate(ndate)
end if
end if
' se non ci sono dati mancanti...
if not errore then
' se ID è maggiore di zero allora si tratta di un AGGIORNAMENTO di dati...
if id > 0 then
sql = "UPDATE tbl_news SET title = '" & ntitle & "', body = '" & nbody & "', date = '" & ndate & "', stato = " & nstatus & " WHERE id = " & id
ntitle = replace(ntitle,"''","'")
nbody = replace(nbody,"''","'")
else
' ... altrimenti si tratta di un NUOVO INSERIMENTO.
sql = "INSERT INTO tbl_news (title, body, date, stato) VALUES('" & ntitle & "', '" & nbody & "', '" & ndate & "', " & nstatus & ")"
ntitle = ""
nbody = ""
ndate = FormatDateTime(Date(),vbGeneralDate)
nstatus = 1
end if
' eseguiamo l'operazione...
conn.execute(sql)
messaggio = "Operazione eseguita correttamente."
end if
else
' se ID è maggiore di zero vuol dire che si tratta di una MODIFICA e quindi dobbiamo prendere idati dal db e metterli nel FORM per farli mdoficare all'utente...
if id > 0 then
sql = "SELECT * FROM tbl_news WHERE id = " & id
set rs = server.createObject("ADODB.Recordset")
rs.open sql, conn, 1, 2
if not rs.eof then
ntitle = rs("title")
nbody = rs("body")
ndate = rs("date")
nstatus = rs("stato")
end if
rs.close
set rs = nothing
else
' altrimenti, trattandosi di un NUOVO INSERIMENTO, avremo campi vuoti nel form.
ntitle = ""
nbody = ""
ndate = FormatDateTime(Date(),vbGeneralDate)
nstatus = 1
end if
end if
conn.close
set conn = nothing