"" and request.form("delete") <> "true" then post_ids = -6ren">
gpt4 book ai didi

mysql - 如何检查在 ASP 中执行的 SQL 查询是否没有错误?

转载 作者:行者123 更新时间:2023-11-29 01:01:55 26 4
gpt4 key购买 nike

这是我的代码:

if Request.Form("authorize") <> "" and request.form("delete") <> "true" then
post_ids = Request.form("authorize")
ids = split(post_ids, ",")

For i = LBound(ids) to UBound(ids)
sql = "update tbl_comments set authorized = 'true' where comment_id = " & ids(i)
pageDB.execute(sql)
Next

message = "<div id=""succeed""><strong>Updated</strong>: Your comments have been approved.</div>"
end if

我不想将“消息”设置为成功消息,而是想按照...

if(pageDB.execute(sql) was succesful) then
message = "<div id=""succeed""><strong>Updated</strong>: Your comments have been approved.</div>"
else
message = "<div id=""error""><strong>Error</strong>: Your comments have not been approved.</div>"
end if

最佳答案

您需要将 pageDB.execute(sql) 放在 try catch block 中

像这样

message = "<div id=""succeed""><strong>Updated</strong>: Your comments have been approved.</div>"
Try
pageDB.execute(sql)
Catch ex as Exception
message = "<div id=""error""><strong>Error</strong>: Your comments have not been approved.</div>"
End Try

正如你问题下的评论所暗示的那样,你不应该像这样更新 SQL 数据库,因为你将你的数据库暴露给黑客攻击(很容易被黑客攻击)

考虑使用命令参数。网上有很多关于此的内容。

编辑

既然我们正在谈论经典的 ASP 错误处理,它并不那么容易,但仍然是可能的。这是一个更大的主题,所以我建议您看看这篇文章。

http://www.15seconds.com/issue/990603.htm

pageDB 是什么类型的对象?

关于mysql - 如何检查在 ASP 中执行的 SQL 查询是否没有错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2577843/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com