PDA

View Full Version : Syntax error in INSERT INTO statement.


BarrMan
12-03-2005, 05:49 PM
<%If Request.Form("Body") = "" Then
Response.Write "You haven't inserted a body."
Response.End
End If

Dim Conn, Rs, SQL, user_id
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "PROVIDER=Microsoft.JET.OLEDB.4.0;Data Source=" & server.MapPath("includes/database.mdb")
Set rs = Server.CreateObject("ADODB.RecordSet")
Rs.Open "SELECT * FROM users WHERE username='" & Session("username") & "'", conn
user_id = rs("id")
Rs.Close
SQL = "INSERT INTO replys([title], [body], [time], [date], [username], [fid], [tid], user_id)" & _
"VALUES('" & strFormat(Request.Form("title")) & "','" & strFormat(Request.Form("Body")) & _
"','" & time() & "',#" & date() & "#,'" & Session("username") & "'," & _
Request.Form("Forum") & "," & Request.Form("thread") & "," & user_id & ")"
Conn.Execute SQL
Set Conn = Nothing
If Err.number <> 0 Then
Response.Write Err.Description
Else
SQL = "SELECT * FROM users WHERE username='" & session("username") & "'"
Rs.Open SQL, Conn
Dim posts
Posts = rs("posts") + 1
Rs.Close
SQL = "UPDATE users SET posts=" & posts & " WHERE username='" & Session("username") & "'"
Conn.Execute SQL
'Rs.Open "SELECT * FROM ReplysQ WHERE
'Response.Redirect "showthread.asp?id=" & Request.Form("thread") & "&fid=" & Request.Form("forum") & "#" & rs("id")
Set Conn = Nothing
Rs.Close
Set rs = Nothing
End If
%>
Syntax error in INSERT INTO statement.

Can any1 help me?

pramsey
12-03-2005, 06:13 PM
I think you are missing a quotation mark at the end of the values line.

Try replacing the red text
SQL = "INSERT INTO replys([title], [body], [time], [date], [username], [fid], [tid], user_id)" & _
"VALUES('" & strFormat(Request.Form("title")) & "','" & strFormat(Request.Form("Body")) & _



With this

"VALUES('" & strFormat(Request.Form("title")) & "','" & strFormat(Request.Form("Body")) " & _

BarrMan
12-04-2005, 05:28 PM
thx for the reply but that wasn't the problem... the problem was that some variable was missing... i think the thread id but i'm not sure... anyway... i fixed it.