SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old May 27th, 2004, 10:53 AM
Phlash Phlash is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 8 Phlash User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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
%>

Reply With Quote
  #2  
Old May 27th, 2004, 11:32 AM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 13
Not farmilar with MySQL yet, but..

Try

strInsertSQL = "INSERT INTO [News] (Headline, Post, [Post-By], Date) VALUES ('" & strHeadline & "','" & strPost & "','" & strUser & "','" & strDate & "')"

S-

Reply With Quote
  #3  
Old May 27th, 2004, 11:43 AM
Phlash Phlash is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 8 Phlash User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Nah, same error

Reply With Quote
  #4  
Old May 27th, 2004, 11:43 AM
Onslaught Onslaught is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 34 Onslaught User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 44 sec
Reputation Power: 6
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.

Reply With Quote
  #5  
Old May 27th, 2004, 12:02 PM
Phlash Phlash is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 8 Phlash User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #6  
Old May 27th, 2004, 12:41 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
Click here for more information.
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,781 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 45 m 55 sec
Reputation Power: 470
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.

Reply With Quote
  #7  
Old May 27th, 2004, 01:08 PM
Phlash Phlash is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 8 Phlash User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I changed the SQL to
strSql = "INSERT INTO [News] (Headline) VALUES('" & strHeadline & "')"
and i still get the same error

Reply With Quote
  #8  
Old May 27th, 2004, 01:10 PM
Phlash Phlash is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 8 Phlash User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I removed the [] and it seems to work, thanks for all the help though

Reply With Quote
  #9  
Old May 27th, 2004, 03:00 PM
Onslaught Onslaught is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 34 Onslaught User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 44 sec
Reputation Power: 6
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 ~.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Trouble inserting a record


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT