troubles with INSERT

S

shank

Can anyone see anything wrong with this INSERT code? It doesn't INSERT and I
get the following error when I try to submit data...

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]The name 'Sammy' is not
permitted in this context. Only constants, expressions, or variables allowed
here. Column names are not permitted.
Line 20

I was using the name Sammy in the fname form field.

<%
varFname = Request("fname")
varEmail = Request("email")
varCountry = Request("country")
varOrderno = Request("orderno")
varPrice = Request("price")
varComments = Request("comments")
%>
<%
Dim DataConn, SQL
Set DataConn = Server.CreateObject("ADODB.Connection")
DataConn.Open SQL_STRING
SQL = "INSERT INTO IntCC ([Fname], , [Country], [OrderNo], [Price],
[Comments]) "
SQL = SQL & "VALUES (" & varFname & ", " & varEmail & ", " & varCountry & ",
" & varOrderno & ", " & varPrice & ", " & varComments & ") "
DataConn.Execute(SQL) <-- This is Line 20
%>
 
A

Aaron Bertrand - MVP

You need to denote string values with string delimiters.

sql = "INSERT ... VALUES('" & varFName & "', ...")

Also, beware of SQL injection! Replace ' with '' in all your strings that
come from anywhere if you're going to build dynamic SQL strings instead of
stored procedures.

To see why, create a table called foo with 10 rows of data, then hit your
page this way:

http://yourserver/yourfile.asp?fname='');DELETE+foo;--

Hint: use stored procedures.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top