0

因此,我试图让管理员能够使用条件 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>
4

1 回答 1

3

您正在<form>为每个评论生成一个,而不是<form>包含评论的所有单选按钮。而且您的删除按钮位于所有表单之外。它提交的是哪个表格?

于 2013-11-03T09:33:28.140 回答