p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0

Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 17th, 2007, 08:32 AM
Authorized User
Points: 150, Level: 2
Points: 150, Level: 2 Points: 150, Level: 2 Points: 150, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2006
Location: Colorado Springs, CO
Posts: 36
Thanks: 1
Thanked 0 Times in 0 Posts
Default Syntax Error on Insert

I'm getting a syntax error on the line below when trying to do an insert into a SQL database:

set rsInsert = conn.Execute ("INSERT INTO user (lastname, firstname, grade) values ('" & lastname & "', '" & firstname & "', '" & grade & "' ")

The exact error:

[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near the keyword 'user'.

Any help is appreciated!

Thanks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old April 17th, 2007, 08:39 AM
Wrox Author
Points: 12,801, Level: 49
Points: 12,801, Level: 49 Points: 12,801, Level: 49 Points: 12,801, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Akron, Ohio, USA.
Posts: 4,023
Thanks: 1
Thanked 42 Times in 42 Posts
Send a message via AIM to dparsons
Default

Since the string 'user' doesn't exist in the above sql statement I assume that this has to do with the data you are passing into your sql statement.

the most common problem could be that the string you are trying to insert contains an ' which is causing a premature termination of the string.

Do a response.write of the sql statemetn so that you can look at what its literal value is.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old April 17th, 2007, 09:15 AM
Authorized User
Points: 150, Level: 2
Points: 150, Level: 2 Points: 150, Level: 2 Points: 150, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2006
Location: Colorado Springs, CO
Posts: 36
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Here's my complete piece of code:

Dim lastname, firstname, grade, data_source, con, rsinsert, Conn

Function ChkString(string)
If string = "" Then string = " "
ChkString = Replace(string, "'", "'")
End Function

lastname = ChkString(Request.Form("lastname"))
firstname = ChkString(Request.Form("firstname"))
grade = ChkString(Request.Form("grade"))
set Conn=Server.CreateObject("ADODB.Connection")
set rsInsert = server.CreateObject("ADODB.Recordset")
Conn.open "Driver={SQL Server}; Server=server;Database=db;UID=x;PWD=x;"
set rsInsert = conn.Execute ("INSERT INTO user (lastname, firstname, grade) values ('" & lastname & "', '" & firstname & "', '" & grade & "' ")


con.Close
Set con = Nothing

I'm not sure what you mean by doing a response.write of the SQL statement.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old April 17th, 2007, 09:22 AM
Wrox Author
Points: 12,801, Level: 49
Points: 12,801, Level: 49 Points: 12,801, Level: 49 Points: 12,801, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Akron, Ohio, USA.
Posts: 4,023
Thanks: 1
Thanked 42 Times in 42 Posts
Send a message via AIM to dparsons
Default

This has nothing to do with your code *i think*. By response.write of your sql statement, instead of this:

set rsInsert = conn.Execute ("INSERT INTO user (lastname, firstname, grade) values ('" & lastname & "', '" & firstname & "', '" & grade & "' ")

do this:
Response.Write("INSERT INTO user (lastname, firstname, grade) values ('" & lastname & "', '" & firstname & "', '" & grade & "' ")")

Also, in your SQL sytnax above, you are missing a closing " and ) at the end of the insert statement.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old April 17th, 2007, 09:33 AM
Authorized User
Points: 150, Level: 2
Points: 150, Level: 2 Points: 150, Level: 2 Points: 150, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2006
Location: Colorado Springs, CO
Posts: 36
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Okay, here's the output now:

Microsoft VBScript compilation error '800a0409'

Unterminated string constant

/staneval/insert1.asp, line 20

Response.Write("INSERT INTO user (lastname, firstname, grade) values ('" & lastname & "', '" & firstname & "', '" & grade & "' ")")
-----------------------------------------------------------------------------------------------------------------------------------^


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old April 17th, 2007, 09:40 AM
Wrox Author
Points: 12,801, Level: 49
Points: 12,801, Level: 49 Points: 12,801, Level: 49 Points: 12,801, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Akron, Ohio, USA.
Posts: 4,023
Thanks: 1
Thanked 42 Times in 42 Posts
Send a message via AIM to dparsons
Default

You have a " out of place. I am going to assume that you are a beginner with asp?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #7 (permalink)  
Old April 17th, 2007, 09:52 AM
Authorized User
Points: 150, Level: 2
Points: 150, Level: 2 Points: 150, Level: 2 Points: 150, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2006
Location: Colorado Springs, CO
Posts: 36
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Fairly new to ASP. Came from the Cold Fusion world and now trying to pick up ASP.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #8 (permalink)  
Old April 17th, 2007, 09:58 AM
Wrox Author
Points: 12,801, Level: 49
Points: 12,801, Level: 49 Points: 12,801, Level: 49 Points: 12,801, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Akron, Ohio, USA.
Posts: 4,023
Thanks: 1
Thanked 42 Times in 42 Posts
Send a message via AIM to dparsons
Default

Ok. Well I am not going to tell you exactly how to fix your error (you aren't going to learn anything from me simply giving you the answer) but the error is occuring in the last 4 characters of your string and, as I said, you have a " out of place.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #9 (permalink)  
Old April 17th, 2007, 10:01 AM
Authorized User
Points: 150, Level: 2
Points: 150, Level: 2 Points: 150, Level: 2 Points: 150, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2006
Location: Colorado Springs, CO
Posts: 36
Thanks: 1
Thanked 0 Times in 0 Posts
Default

I have no idea what "out of place" means.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #10 (permalink)  
Old April 17th, 2007, 10:08 AM
Authorized User
Points: 150, Level: 2
Points: 150, Level: 2 Points: 150, Level: 2 Points: 150, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2006
Location: Colorado Springs, CO
Posts: 36
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Found the problem but still don't know what out of place means.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax error when using "Insert Into" Luis Access VBA 14 November 18th, 2008 03:09 PM
Syntax error INSERT INTO ITladybug ADO.NET 2 January 31st, 2006 07:50 AM
Syntax error in INSERT INTO statement. kingleon Classic ASP Basics 1 May 10th, 2005 07:25 PM
Syntax error in INSERT INTO statement Stephan BOOK: Beginning JavaScript 16 February 22nd, 2005 01:43 PM
INSERT syntax error ss2003 PHP Databases 1 October 7th, 2004 06:30 PM



All times are GMT -4. The time now is 09:12 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc