PDA

View Full Version : syntax error, can't figure it out


CdnGal
12-03-2002, 02:49 AM
Hi, there


Can someone please try see what is wrong with my code. (newbie here taking a class) Basically it's little "form" where a user enters their e-mail address, fname, lname, password and keyword....and it's supposed to add this information to my Access Database. The error I get says "Syntax Error (missing operator) in query expression "undefined", "John""
Also, the line it "points" to is the one that says:
oC.execute(strSQL)

(John would be the fname that was entered into the form)

There are a few files involved...I'm not sure if you'll need them all to see what's causing the problem....so I've attached the one that is indicated in the syntax error.

THanks VERY much!
Majorly Confused
____________________________________

<%@language=javascript%>
<%Response.Buffer=true%>
<!--#include file="emailconx.inc"-->
<!--#include file="adojavas.inc"-->
<html><head>
<title>Add Customer</title>
</head>
<body>
<h1>Add Customer</h1>
<% var email,fname,lname,pwd,keyword,sessID,signup, SQL
email = Request.Form("email")
fname = Request.Form("fname")
lname = Request.Form("lname")
pwd = Request.Form("pwd")
keyword = Request.Form("keyword")
sessID = Session.SessionID
signup = new Date()

oC = Server.CreateObject("ADODB.connection")
oRS = Server.CreateObject("ADODB.recordset")
oC.Open(CS);
SQL = "SELECT * FROM customer"
oRS.Open(SQL,oC,adOpenDynamic,adLockOptimistic,adCmdText)
strSQL ="INSERT INTO CUSTOMER "+ "(email,sessID,fname,lname,pwd, keyword, signup)" +
" values (" +
"'" + Request.Form("email") + "','" +
"'" + Request.Form("sessID") + "','" +
"'" + Request.Form("fname") + "','" +
"'" + Request.Form("lname") + "','" +
"'" + Request.Form("pwd") + "','" +
"'" + Request.Form("keyword") + "','" +
"'" + Request.Form("signup") + "')" ;

oC.execute(strSQL)

Response.Write(SQL) ***does this need to be here? the instructor shows it

oRS.Close();
oC.Close();
%>
<a href = "CEmailADODisplay.asp">
Display the customer list </a>
</body></html>

glenngv
12-03-2002, 03:01 AM
to debug the SQL statement, it is always helpful to output the statement before executing it.

Response.Write(SQL)
oC.execute(strSQL)

and why do you still used Request.Form in the SQL statement when you already put each of them in a variable?

also you should check for single quotes in the input because this will cause a syntax error in the SQL statement. You may want to look at whammy's sticky post below:

http://www.codingforums.com/showthread.php?s=&threadid=9843

Since you are using Javascript instead of VBScript, not sure if you will double the single quotes or make them \'

CdnGal
12-03-2002, 03:34 AM
Thanks....

I don't know why I used Request.Form when I had set up variables. I took that out and used just the variable names instead, and it seemed to work fine.

Thanks again!!

glenngv
12-03-2002, 03:50 AM
That is because you use this:

"'" + Request.Form("sessID") + "','" +
"'" + Request.Form("signup") + "')" ;

but sessID and signup are not post data but only variables:

sessID = Session.SessionID
signup = new Date()