Trying to write UPDATE back to SQL in ASP - Incorr

2019-09-21 00:46发布

I'm a bit green when it comes to Classic ASP, so I apologize in advance.

I have an asp page with a form that gets filled in with details of pc equipment. this then adds it to the SQL database. Works a charm...

However, on the view page where we can then change any of the details, when I click the "save changes" button I get an error.

Incorrect syntax near '='

Here is what I have:

<!-- #include file="Tauthenticate.asp" -->

<!--#include file="database.asp"-->

<%

pcname=request.form("T1")
pctype=request.form("T2")
pccpu=request.form("T3")
pcram=request.form("T4")
pcmake=request.form("T5")
pcmodel=request.form("T5b")
pcdate=request.form("T6")
graphics=request.form("T7")
notes=request.form("T8")
tag=request.form("T9")
cd_dvd=request.form("T10")


sqlq = "UPDATE PC set PC_Name='" & pcname & "', Type='" & pctype & "', CPU='" & pccpu & "', RAM='" & pcram & "', Make='" & pcmake & "', Model='" & pcmodel & "', Date='" & pcdate & "', Graphics='" & graphics & "', Notes='" & notes & "', Service_Tag='" & tag & "', CD_DVD='" & cd_dvd & "' where PC_ID=" & pcid
response.write(sqlq)
conn.execute(sqlq)
Response.Redirect("../PCs/PCView.asp?pc=" & pcid)



%>

After a quick test, i get this result

UPDATE PC set PC_Name='LRW9999', Type='Desktop PC', CPU='blah blah', RAM='5555', Make='blah blah', Model='doo doo', Date='09/02/16', Graphics='blah blah', Notes='test only', Service_Tag='gyudsgysdgsgghfs', CD_DVD='9999' where PC_ID=

Microsoft OLE DB Provider for SQL Server error '80040e14'

Incorrect syntax near '='.

/PCs/SaveChangesnew.asp, line 28

Where am I going wrong? It seems I can't see the wood for the trees and I need fresh eyes to help me.

1条回答
太酷不给撩
2楼-- · 2019-09-21 01:21

Update your sqlquery to following:

sqlq = "UPDATE PC set PC_Name='" & pcname & "', Type='" & pctype & "', CPU='" & pccpu & "', RAM='" & pcram & "', Make='" & pcmake & "', Model='" & pcmodel & "', Date='" & pcdate & "', Graphics='" & graphics & "', Notes='" & notes & "', Service_Tag='" & tag & "', CD_DVD='" & cd_dvd & "' where PC_ID='" & pcid &"'"
查看更多
登录 后发表回答