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

April 17th, 2007, 08:32 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Location: Colorado Springs, CO
Posts: 36
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, 08:39 AM
|
|
Wrox Author
Points: 12,827, Level: 49 |
|
|
Join Date: Oct 2005
Location: Akron, Ohio, USA.
Posts: 4,029
Thanks: 1
Thanked 42 Times in 42 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, 09:15 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Location: Colorado Springs, CO
Posts: 36
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, 09:22 AM
|
|
Wrox Author
Points: 12,827, Level: 49 |
|
|
Join Date: Oct 2005
Location: Akron, Ohio, USA.
Posts: 4,029
Thanks: 1
Thanked 42 Times in 42 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, 09:33 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Location: Colorado Springs, CO
Posts: 36
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, 09:40 AM
|
|
Wrox Author
Points: 12,827, Level: 49 |
|
|
Join Date: Oct 2005
Location: Akron, Ohio, USA.
Posts: 4,029
Thanks: 1
Thanked 42 Times in 42 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, 09:52 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Location: Colorado Springs, CO
Posts: 36
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, 09:58 AM
|
|
Wrox Author
Points: 12,827, Level: 49 |
|
|
Join Date: Oct 2005
Location: Akron, Ohio, USA.
Posts: 4,029
Thanks: 1
Thanked 42 Times in 42 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, 10:01 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Location: Colorado Springs, CO
Posts: 36
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
I have no idea what "out of place" means.
|

April 17th, 2007, 10:08 AM
|
|
Authorized User
|
|
Join Date: Jun 2006
Location: Colorado Springs, CO
Posts: 36
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Found the problem but still don't know what out of place means.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |