Error Type: Microsoft VBScript compilation (0x800A0401)
Hi... im trying to add a new record onto my database. However, i keep on getting this error message
Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/CTs2/test1.asp, line 14, column 45
sql="INSERT INTO testTable (myname) VALUES ("Request.Form("myname")")"
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "C:\Documents and Settings\CTSLab\Desktop\lab webby\webby 2\test1.mdb"
sql="INSERT INTO testTable (myname) VALUES ("Request.Form("myname")")"
on error resume next
conn.Execute sql,recaffected
if err<>0 then
Response.Write("No update permissions!")
else
Response.Write("<h3>" & recaffected & " record added</h3>")
end if
conn.close
%>
I see two things wrong with the Sql insert statement itself. 1st, You are stoping the Insert with the double Quote " but then do not use the concatenation operator to add the form value and then have the double quote again immediately after the form value. Also if this is not a numeric datatype for the datafield you need to enclose the info in single quotes. like so
Code:
sql="INSERT INTO testTable (myname) VALUES ('" & Request.Form("myname") & "')"
Also recaffected is not used.
When you use the Execute method of the connection object there is only one parameter passed and that is the sql query.
Also using this kind of insert opens you up to SQL interjection attacks. (that is where someone tries to take control of your database) The following will help prevent it. Since this is an Access database the part of the function that replaces the double dashes isn't needed but it doesn't hurt to have it in there.
i did what you asked me to do earlier and it worked perfectly. When i tried to apply what you said to my main code... i keep on getting "No Update Permission!"
Im pretty sure im doing something wrong.... hope you can help me with this...
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "C:\Documents and Settings\CTSLab\Desktop\lab webby\webby 2\LabApp.mdb"
on error resume next
conn.Execute(sql)
if err<>0 then
Response.Write("No update permissions!")
else
Response.Write("<h3>" & recaffected & " record added</h3>")
end if
conn.close 'closes object
Set conn =Nothing 'clears object from memory
%>
I'm having an error in SQL part. I'm using ASP 2003 and SQL Server 7.0. This is my error.
Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/Crystal_1/productlist.asp, line 19, column 23
"ORDER BY product_name",
------------------------^
I'm having an error in SQL part. I'm using ASP 2003 and SQL Server 7.0. This is my error.
Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/Crystal_1/productlist.asp, line 19, column 23
"ORDER BY product_name",
------------------------^
Remove the , at the end of the conn= statement
Code:
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Driver={SQL Server};" &_
"Server=Aurora;" &_
"Database=CRYSTAL;" &_
"Uid=sa;" &_
"Pwd=;"
Set conn= Server.CreateObject("ADODB.Recordset")
conn="SELECT product_id,product_picture,product_name,product_briefDesc " &_
"FROM Product WHERE product_category= '" &cat& "' " &_
"AND status=1" &_
"ORDER BY product_name",
I got the same error message. you said I removed the code field
I didnt understand which code field did you remove
if you had these codes can u send me
my code is:
<%
Private Function preventInjection(ByRef theString)
theString = Replace(theString, ";", ";") 'removes semicolon
theString = Replace(theString, "'", "'") 'removes lone apostrophe's '
theString = Replace(theString, "--", "--") 'removes double dash sql comment
preventInjection = theString
End Function
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "C:\Inetpub\wwwroot\seref\ozo.mdb"
sql="INSERT INTO test (ad,soyad) VALUES ('" & preventInjection(Request.Form("ad")) & "','" & preventInjection(Request.Form("soyad")) & "')"
on error resume next
conn.Execute(sql)
if err<>0 then
Response.Write("No update permissions!")
else
Response.Write("<h3>" & recaffected & " record added</h3>")
end if
conn.close 'closes object
Set conn =Nothing 'clears object from memory
%>