I'm fairly new to ASP, and need some help figuring out this error.

The 'ThingsNeeded.asp' page holds 4 buttons and passes the required 'ID' value, keeping the user to just update their record. I have two pages done, but keep getting

Incorrect syntax near the keyword 'WHERE'. 
/PPmanual/AFLocations.asp, line 23

Line 23 is: SQL = SQL & "WHERE ID = '" & rs("ID") & "'"

The page that works perfectly (updates the record) has this code:

Set rs = Server.CreateObject("ADODB.RecordSet")
SQL = "SELECT * FROM APPLogin WHERE ID = " & request("ID")
rs.Open SQL, conn, AdOpenStatic, AdLockOptimistic
	
If request("Submit") <> "" then
SQL = "UPDATE APPLogin SET "
SQL = SQL & "Q1 = '" & request("Q1") & "', "
SQL = SQL & "Q2 = '" & request("Q2") & "', "
SQL = SQL & "Q3 = '" & request("Q3") & "', "
SQL = SQL & "Q4 = '" & request("Q4") & "', "
SQL = SQL & "Q5 = '" & request("Q5") & "', "
SQL = SQL & "Q6 = '" & request("Q6") & "', "
SQL = SQL & "Q7 = '" & request("Q7") & "', "
SQL = SQL & "Q8 = '" & request("Q8") & "' " 
SQL = SQL & "WHERE ID = '" & rs("ID") & "'"
conn.Execute SQL
response.redirect("ThingsNeeded.asp")
End If

The page that generates the error has this code:

Set rs = Server.CreateObject("ADODB.RecordSet")
SQL = "SELECT * FROM APPLogin WHERE ID = " & request("ID")
rs.Open SQL, conn, AdOpenStatic, AdLockOptimistic

If request("Submit") <> "" then
SQL = "UPDATE APPLogin SET "
SQL = SQL & "AFLocation1 = '" & request("AFLocation1") & "', "
SQL = SQL & "AFName1 = '" & request("AFName1") & "', "
SQL = SQL & "AFAddress1 = '" & request("AFAddress1") & "', "
SQL = SQL & "AFCity1 = '" & request("AFCity1") & "', "
SQL = SQL & "AFState1 = '" & request("AFState1") & "', "
SQL = SQL & "AFZip1 = '" & request("AFZip1") & "', "
SQL = SQL & "AFTelephone1 = '" & request("AFTelephone1") & "', "
SQL = SQL & "AFFax1 = '" & request("AFFax1") & "', "
SQL = SQL & "AFDirector1 = '" & request("AFDirector1") & "', "
SQL = SQL & "AFManager1 = '" & request("AFManager1") & "', "
SQL = SQL & "WHERE ID = '" & rs("ID") & "'"

response.write(sql)
conn.Execute SQL
'	response.redirect("ThingsNeeded.asp")
End If

The 'response.write(sql)' generates this line, which is correct: UPDATE APPLogin SET AFLocation1 = '1', AFName1 = 'John Doe', AFAddress1 = '1122 3rd Ave', AFCity1 = 'Walla Walla', AFState1 = 'ID', AFZip1 = '23456', AFTelephone1 = '321-654-9870', AFFax1 = '654-987-2581', AFDirector1 = 'Burt Bender', AFManager1 = 'Jane Smith', WHERE ID = '1' I don't understand why the second page is generating the error, the coding is the same as the first page, and the first page works. I do have a 'Rs.Close' at the end of each page, so I am closing the recordset. I've tried a couple of different things, like &_ after my SQL=SQL statements, changing the WHERE ID = '" & rs("ID") & "' to WHERE ID = '" & request("ID") & "', things like that.

I'm hoping someone can look at this and see what I've been missing. I'm sure it's probably small, and I'm sure I've overlooked it. I think I've just looked at it so long I'm no longer seeing it right. If you need to see more code, just let me know.

Thanks in advance
Jackie

I just found it. An extra comma on the line before my WHERE statement.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.