|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Trouble inserting a record
Hey, i'm trying to insert record into a mysql Database and i keep getting the following error:
ADODB.Connection.1error '80004005' SQLState: 42000 Native Error Code: 1064 [TCX][MyODBC]You have an error in your SQL syntax near '[News] (Headline, Post, Post-By, Date) VALUES ('This is the Headline','Eat this ' at line 1 /~boombox/Update/add_post.asp, line 63 Heres the Code: <% strDate = Request.Form("Date") strDate = DatePart("YYYY", strDate) & "/" & DatePart("M", strDate) & "/" & DatePart("D", strDate) strHeadline = Request.Form("HeadLine") strPost = Request.Form("Post") strPost = replace(strPost, vbcrlf,"<br>") strPost = replace(strPost, "'","|") strPost = replace(strPost, "''","||") StrUser = Request.Form("PBY") strPassword = Request.Form("Password") Response.Write "<B>Date</B>: " & strDate & "<BR>" & "<BR>" Response.Write "<B>Headline</B> : " & strHeadline & "<BR>" Response.Write "<B>Post</B> :" & "<BR>" & strPost & "<BR>" & "<BR>" Response.Write "<B>User</B> : " & strUser & "<BR>" Response.Write "<B>Password</B> :" & strPassword Response.Write "<BR>" & "<BR>" & "<BR>" Set oConn = Server.CreateObject("ADODB.Connection") oConn.Open "Driver={MySQL}; DATABASE=myDB;UID=myDB; PASSWORD=pass;" sSQL = "Select [Password] From [Users] WHERE [Username]='" & strUser & "'" Set rsCheckPass = oConn.Execute(sSQL) Do While Not rsCheckPass.EOF strGotPass = rsCheckPass("Password") If strGotPass = strPassword Then Response.Write "Username and Password accepted..." & "<BR>" & "<BR>" blnPasswordAccept = True Else Response.Write "Username and Password DENIED." & "<BR>" & "<BR>" blnPasswordAccept = False End If rsCheckPass.MoveNext Loop rsCheckPass.Close Set rsCheckPass = Nothing If blnPasswordAccept = True Then strInsertSQL = "INSERT INTO [News] (Headline, Post, Post-By, Date) VALUES ('" & strHeadline & "','" & strPost & "','" & strUser & "','" & strDate & "')" Response.Write strInsertSQL Set AddNews = oConn.Execute(strInsertSQL) AddNews.Close Set AddNews = Nothing Else End If oConn.Close Set oConn = Nothing %> |
|
#2
|
|||
|
|||
|
Not farmilar with MySQL yet, but..
Try strInsertSQL = "INSERT INTO [News] (Headline, Post, [Post-By], Date) VALUES ('" & strHeadline & "','" & strPost & "','" & strUser & "','" & strDate & "')" S- |
|
#3
|
|||
|
|||
|
Nah, same error
![]() |
|
#4
|
|||
|
|||
|
You can also use back-ticks ` to surround column/table names instead of brackets.
strInsertSQL = "INSERT INTO `News` (`Headline`, `Post`, `Post-By`, `Date`) VALUES ('" & strHeadline & "','" & strPost & "','" & strUser & "','" & strDate & "')" Also, I would change the column name Date to something other than a reserve word. It is never a good idea to have a reserver word as a column name in a database. |
|
#5
|
|||
|
|||
|
Thanks for the help, but it still isnt working
![]() Same error. I ahve changed the date field to PDate. Heres the contents of the SQL before it tries to insert it INSERT INTO [News] ('Headline', 'Post', 'Post-By', 'PDate') VALUES ('This is the Headline','Eat this multi-linePost','JD','2004/5/27') Erm there is another field in the database called ID that i have got set to auto increment, does this matter? |
|
#6
|
||||
|
||||
|
Step through the code, try adding one field at a time, then you will know which field is causing the issue.
Example: Code:
strSql = "INSERT INTO [News] (Headline) VALUES('" & strHeadline & "')"
Conn.Execute(strSql)
If this works, then add the next field Code:
strSql = "INSERT INTO [News] (Headline, Post) VALUES('" & strHeadline & "', '" & strPost & "')"
Conn.Execute(strSql)
And continue until you discover which field is causing the problem. |
|
#7
|
|||
|
|||
|
I changed the SQL to
strSql = "INSERT INTO [News] (Headline) VALUES('" & strHeadline & "')" and i still get the same error |
|
#8
|
|||
|
|||
|
I removed the [] and it seems to work, thanks for all the help though
![]() |
|
#9
|
|||
|
|||
|
Also, it isn't single quotes ' but backticks `. It is an important difference.
On a qwerty keyboard, it is the key to the left of the 1 key unshifted. Shifted is the tilde ~. |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > Trouble inserting a record |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|