所以我试图让管理员能够使用条件if语句删除帖子上的评论。在阶段1中,管理员可以选择与每个帖子关联的单选按钮,其值应传递到第2阶段,通过deleteComment
变量将其删除。但是,我调试了该语句,打印出来说没有数据传递:
从Commentstable中删除*,其中ID =
Microsoft JET数据库引擎错误“80040e14”
查询表达式'ID ='中的语法错误(缺少运算符)。
/courses/benv/2410/2013s2/3420384/assign4/post.asp,第138行
以下代码。
<% option explicit %>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="normalize.css">
<script src="jquery.js"></script>
<link rel="stylesheet" type-"text/css" href="960_12_col.css">
<link rel="stylesheet" type-"text/css" href="style.css">
</head>
<body>
<!--#include file="header.asp"-->
<!--#include file="dbconn.asp"-->
<div class="content">
<div class="content-inner container_12">
<div class="wrapper prefix_2 grid_8 suffix_2">
<%
dim pic
pic = request.querystring("i")
if pic="" then pic="1"
dim stage, s
stage = request.form("stage")
if stage = "" then stage=1
dim SQL, info
' 0 1 2 3 4 5 6
SQL = "select ProjectsTable.ID, projectName, Projectstable.description, pictureURL, username, category, created "&_
"from ProjectsTable, usertable, categorytable "&_
"where ProjectsTable.usernum = usertable.id AND ProjectsTable.categorynum = categorytable.id "&_
"and projectstable.id="&pic
set info=conn.execute(SQL)
if info.eof then
response.write "No data found."
end if
response.write "<div class=""post"">"&_
"<h1>" & info(1) & "</h1>"&_
"<ul class=""byline"">"&_
"<li> By " & info(4) & "</li>"&_
"<li> on " & info(6) & "</li>"&_
"<li> in " & info(5) & "</li>"&_
"</ul>"&_
"<a class=""feature-image"" href=""post.asp?i=" & info(0) & """>" &_
"<img src=" & info(3)&"""></a><br>"&_
"<p>" & info(2) & "</p>"
response.write "<h3> Comments </h3>"
'------------------------------------------------------------------
if stage = 1 then
'------------------------------------------------------------------
if Session("username")="" then
Response.write "<a href=login.asp>Login to comment</a>"
else
response.write "<form action="""" method=""post"">" &_
"<input type=""hidden"" name=""stage"" value=""2"">" &_
"<label for=""post"">Comment</label>" &_
"<textarea id=""post"" name=""comment""></textarea><br>" &_
"<input id=""add-comment"" class=""button"" type=""submit"" value=""Add comment"">" &_
"</form><br>"
end if
' 0 1 2 3
sql = "select commentstable.id, comment, commentDate, username " &_
"from CommentsTable, usertable " &_
"where usertable.id = commentstable.usernum " &_
"AND projectNum="&pic &_
" order by commentDate DESC"
set info=conn.execute(SQL)
if info.eof then
response.write "No Comments."
else
if Session("usertype")="2" then
do
response.write "<form action=""post.asp"" method=""post"">"&_
"<input type=""hidden"" name=""stage"" value=""2"">"&_
"<label for=""delete""></label>"&_
"<input id=""delete"" type=""radio"" name=""commentobedeleted"" value=""" &_
info(0) & """>"&_
info(3) & " Posted at: " & info(2) & " " & info(1) &_
"<br>" &_
"</form>"
info.movenext
loop until info.eof
response.write "<input class=""button"" type=""button"" value=""Delete Comment"">"
else
do
response.write "<p>" & info(3) & " Posted at: " & info(2) & " " & info(1) & "</p>"
info.movenext
loop until info.eof
end if
end if
'--------------------------------------------------------------------
elseif stage = 2 then
'--------------------------------------------------------------------
dim deleteComment
deleteComment = Request.Form("commentobedeleted")
sql = "delete * from Commentstable where ID="&deleteComment
response.write(SQL)
conn.execute(sql)
response.write "<p>Comment deleted.</p>"
dim comment, u, uid, p_info
comment=Request.Form("comment")
u=Session("username")
' 0
sql = "select usertable.id "&_
"from usertable where username='"&u&"'"
set info=conn.execute(sql)
uid = info(0)
sql="insert into CommentsTable (comment, usernum, projectNum) "&_
"values ('" & comment & "', " & uid & ", " & pic & ")"
conn.execute sql
' 0
sql = "select projectstable.id "&_
"from projectstable "
set p_info=conn.execute(sql)
sql="insert into CommentsTable (projectNum) "&_
"values (" & p_info(0) & ")"
conn.execute sql
' 0 1 2 3
sql = "select CommentsTable.ID, comment, commentDate, username " &_
"from CommentsTable, usertable " &_
"where usertable.id = commentstable.usernum " &_
"AND projectNum="&pic &_
" order by commentDate DESC"
set info=conn.execute(SQL)
response.write "<form action="""" method=""post"">" &_
"<input type=""hidden"" name=""stage"" value=""2"">" &_
"Comment: " &_
"<textarea id=""post"" name=""comment""></textarea><br>" &_
"<input id=""add-comment"" class=""button"" type=""submit"" value="" add comment "">" &_
"</form>"
if info.eof then
response.write "No Comments."
end if
if Session("usertype")="2" then
do
response.write "<form action=""post.asp"" method=""post"">"&_
"<input type=""hidden"" name=""stage"" value=""2"">"&_
"<label for=""delete""></label>"&_
"<input id=""delete"" type=""radio"" name=""commentobedeleted"" value=""" &_
info(0) & """>"&_
info(3) & " Posted at: " & info(2) & " " & info(1) &_
"<br>" &_
"</form>"
info.movenext
loop until info.eof
response.write "<input class=""button"" type=""button"" value=""Delete Comment"">"
else
do
response.write "<p>" & info(2) & " Posted at: " & info(1) & " " & info(0) & "</p>"
info.movenext
loop until info.eof
end if
'------------------------------------------------------------------
end if ' stage
'------------------------------------------------------------------
conn.close
%>
</div>
</div>
</div>
</div>
<!--#include file="footer.asp"-->
</body>
</html>
答案 0 :(得分:3)
您为每条评论生成一个<form>
,而不是一个<form>
,其中包含评论的所有单选按钮。您的删除按钮位于所有表单之外。提交哪种表格?