 |
| 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
|
|
|
|

April 17th, 2007, 07:32 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
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
|
|

April 17th, 2007, 07:39 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
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
================================================== =========
|
|

April 17th, 2007, 08:15 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
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.
|
|

April 17th, 2007, 08:22 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
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
================================================== =========
|
|

April 17th, 2007, 08:33 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
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 & "' ")")
-----------------------------------------------------------------------------------------------------------------------------------^
|
|

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

April 17th, 2007, 08:52 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Fairly new to ASP. Came from the Cold Fusion world and now trying to pick up ASP.
|
|

April 17th, 2007, 08:58 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
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
================================================== =========
|
|

April 17th, 2007, 09:01 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
I have no idea what "out of place" means.
|
|

April 17th, 2007, 09:08 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Posts: 60
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Found the problem but still don't know what out of place means.
|
|
 |