そのため、管理者が条件付き if ステートメントを使用して投稿のコメントを削除できるようにしようとしています。ステージ 1 で、管理者は各投稿に関連付けられたラジオ ボタンを選択できます。その値はステージ 2 に渡され、そこでdeleteComment
変数を通じて削除されます。ただし、ステートメントをデバッグしたところ、渡されたデータがないことが出力されました。
ID= の Commentstable から * を削除
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>