Query Values (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


kitty6 -> Query Values (6/10/2008 13:15:52)

I have a form which posts to a file called submitout.asp
I get the following error:

Number of query values and destination fields are not the same.

Does anyone know why? Thanks.

Here is the code in submitout.asp

mySQL = "INSERT INTO results (Name,HowLong,Reason) VALUES ('"
mySQL = mySQL & StripQuote(Request.Form("Name")) & "','" & StripQuote(Request.Form("HowLong")) & "','" & StripQuote(Request.Form("Reason")) & "','"

'Response.write(mySQL)
'Response.end

set conntemp=server.createobject("adodb.connection")
conntemp.open myDSN
conntemp.execute(mySQL)
conntemp.close








BeTheBall -> RE: Query Values (6/10/2008 14:46:38)

Yes. I know why . . .

Oh, you probably want me to tell you why. You have an extra comma near the end of your SQL so the code expects another value. Try changing the SQL line to:

mySQL = "INSERT INTO results (Name,HowLong,Reason) VALUES ('"
mySQL = mySQL & StripQuote(Request.Form("Name")) & "','" & StripQuote(Request.Form("HowLong")) & "','" & StripQuote(Request.Form("Reason")) & "'"




kitty6 -> RE: Query Values (6/10/2008 18:06:35)

Now when I fill in the form with aaa, I get the following error?

Syntax error in string in query expression ''aaa'''.




BeTheBall -> RE: Query Values (6/10/2008 22:54:10)

and this?

mySQL = "INSERT INTO results (Name,HowLong,Reason) VALUES ('"
mySQL = mySQL & StripQuote(Request.Form("Name")) & "','" & StripQuote(Request.Form("HowLong")) & "','" & StripQuote(Request.Form("Reason")) & "')"




kitty6 -> RE: Query Values (6/16/2008 8:56:38)

Ok, that worked but I added some more fields and changed some things around a bit and now get this error? What am I missing? Thanks.

Microsoft JET Database Engine error '80040e14'

Syntax error in INSERT INTO statement.

/submitout.asp, line 25

Here is my code:

mySQL = "INSERT INTO results (Name,Reason,Option) VALUES ('"
mySQL = mySQL & StripQuote(Request.Form("Name")) & "','" & StripQuote(Request.Form("Reason")) & "','" & StripQuote(Request.Form("Option")) & "')"

set conntemp=server.createobject("adodb.connection")
conntemp.open myDSN
conntemp.execute(mySQL)
conntemp.clos




BeTheBall -> RE: Query Values (6/16/2008 9:43:14)

Name is a reserved word and should be avoided as a field name in your database. However, if you must use it, then you must put brackets around it in your SQL. For example:

mySQL = "INSERT INTO results ([Name],Reason,Option) VALUES ('"
mySQL = mySQL & StripQuote(Request.Form("Name")) & "','" & StripQuote(Request.Form("Reason")) & "','" & StripQuote(Request.Form("Option")) & "')"




kitty6 -> RE: Query Values (6/16/2008 11:25:56)

Ok, I changed it to person instead of name and below is the code but still getting this error:

Syntax error in INSERT INTO statement.

mySQL = "INSERT INTO results (Person,Reason,Category,In,Back) VALUES ('"
mySQL = mySQL & StripQuote(Request.Form("Person")) & "','" & StripQuote(Request.Form("Reason")) & "','" & StripQuote(Request.Form("Category")) & "','" & StripQuote(Request.Form("In")) & "','" & StripQuote(Request.Form("Back")) & "')"

Thanks.




BeTheBall -> RE: Query Values (6/16/2008 14:35:08)

Pretty sure "In" will be a reserved word as well. Try putting that in brackets:

mySQL = "INSERT INTO results (Person,Reason,Category,[In],Back) VALUES ('"
mySQL = mySQL & StripQuote(Request.Form("Person")) & "','" & StripQuote(Request.Form("Reason")) & "','" & StripQuote(Request.Form("Category")) & "','" & StripQuote(Request.Form("In")) & "','" & StripQuote(Request.Form("Back")) & "')"




kitty6 -> RE: Query Values (6/16/2008 18:53:02)

Thanks, that did it.

One more question. How would I pass a hidden fields value? I added the field "Time" but got an error. How would my code look if I used the that field "Time"?

Thanks for all your help!




BeTheBall -> RE: Query Values (6/17/2008 0:10:57)

Time may also be a reserved word. Also, if this is an Access db, then you need to use different delimiters on your field. Something like:

mySQL = "INSERT INTO results (Person,Reason,Category,[In],Back,[Time]) VALUES ('"
mySQL = mySQL & StripQuote(Request.Form("Person")) & "','" & StripQuote(Request.Form("Reason")) & "','" & StripQuote(Request.Form("Category")) & "','" & StripQuote(Request.Form("In")) & "','" & StripQuote(Request.Form("Back")) & "',#" & StripQuote(Request.Form("Time")) & "#)"




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.046875