Wrox Programmer Forums
|
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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 17th, 2007, 07:32 AM
Authorized User
 
Join Date: Jun 2006
Posts: 60
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

 
Old April 17th, 2007, 07:39 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 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
================================================== =========
 
Old April 17th, 2007, 08:15 AM
Authorized User
 
Join Date: Jun 2006
Posts: 60
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.

 
Old April 17th, 2007, 08:22 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 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
================================================== =========
 
Old April 17th, 2007, 08:33 AM
Authorized User
 
Join Date: Jun 2006
Posts: 60
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 & "' ")")
-----------------------------------------------------------------------------------------------------------------------------------^


 
Old April 17th, 2007, 08:40 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 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
================================================== =========
 
Old April 17th, 2007, 08:52 AM
Authorized User
 
Join Date: Jun 2006
Posts: 60
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.

 
Old April 17th, 2007, 08:58 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 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
================================================== =========
 
Old April 17th, 2007, 09:01 AM
Authorized User
 
Join Date: Jun 2006
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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

 
Old April 17th, 2007, 09:08 AM
Authorized User
 
Join Date: Jun 2006
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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






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 06:25 PM
INSERT syntax error ss2003 PHP Databases 1 October 7th, 2004 05:30 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.