你能发现这个SQL错误吗?

时间:2013-11-01 08:30:32

标签: html sql asp-classic vbscript

所以,我正在尝试在网站上添加文章编辑功能,而且我遇到了绊脚石。错误如下:

  

Microsoft JET数据库引擎错误“80040e10”

     

没有给出一个或多个必需参数的值。

     

/courses/benv/2410/2013s2/3420384/assign4/edit.asp,line 130

错误发生在下面代码的第3阶段。特别是在Suburbtable update命令之后。

我添加了一个print语句来尝试和调试,并提出了以下内容:

update SuburbTable set suburb='Kensington', postcode=2033 where projectsTable.ID= 56

以下代码。帮助赞赏。

<% option explicit %>
<html>
<head>
  <link href="normalize.css" rel="stylesheet" type="text/css">
  <link rel="stylesheet" type-"text/css" href="960_12_col.css">
  <link rel="stylesheet" type-"text/css" href="style.css">
</head>
<body>
<!--#include file="dbconn.asp"-->
<!--#include file="header.asp"-->

    <div class="content">

<div class="content-inner container_12">

  <div class="wrapper prefix_2 grid_8 suffix_2">
<%

if Session("username")="" then
  Response.Redirect("Login.asp")
end if

  dim stage, SQL, info
  stage = request.form("stage")
  if stage = "" then stage=1

  '------------------------------------------------------------------
  if stage = 1 then
  '------------------------------------------------------------------

      response.write "<form action=""edit.asp"" method=""post"">" &_
                     "<input type=""hidden"" name=""stage"" value=""2"">"


  '--- create a radio-button list of the posts
  '                     0             1                
  SQL="select ProjectsTable.ID, ProjectName from ProjectsTable order by Created"
  set info=conn.execute(SQL)

  '-- Loop through the recordset to make each entry in the list.
   do while not info.eof 

      response.write "<label id=""Select""for=""radio""></label>"&_
                     "<input id=""radio""type=""radio"" name=""change"" "&_
                     "value="""&info(0)&""">"&info(1)&"<br>"&chr(13)
    info.movenext 
  loop

  response.write "<input class=""button"" type=""submit"" value=""Select!"">" &_
                 "</form>"


  '------------------------------------------------------------------
  elseif stage = 2 then
  '------------------------------------------------------------------

  dim record_num
  record_num=Request.Form("change")
  if record_num="" then response.redirect "?pg=change"

  '                     0             1             2            3       4               5                         
  SQL="SELECT ProjectsTable.ID, ProjectName, Description, suburb, postcode, pictureURL"&_
        " FROM ProjectsTable, SuburbTable, CategoryTable"&_
        " WHERE ProjectsTable.ID= "&record_num &_
        " AND suburbtable.id = SuburbNum AND categorytable.ID = categoryNum"

  set info=conn.execute(SQL)
%>
      <form action="edit.asp" method="post">
        <input type="hidden" name="stage" value="3">
        <input type="hidden" name="ProjectsTable.ID" value="<% =record_num %>">
        <label for="title">Title</label>
        <input id="title" type="text" name="title" value="<% =info(1) %>"><br>
        <label for="image">Image URL</label>
        <input id="image" type="text" name="image" value="<% = info(5) %>"><br>
        <label for="post">Post</label>
        <textarea id="post" name="post"><%=info(2) %></textarea><br>
        <label for="suburb">Suburb</label>
            <input id="suburb" type="text" name="suburb" value="<% =info(3) %>"><br>
        <label for="postcode">Postcode</label>
            <input id="postcode" type="text" name="postcode" value="<% =info(4) %>"><br>

<%
'                   0               1 
sql = "select categorytable.ID, category "&_ 
      "from categorytable "&_ 
      "order by category "

      set info=conn.execute(SQL)

%>
        <label for="category">Category</label>
            <select name="category"> 
        <%
        do until info.eof
        response.write "<option value=""" & info(0) & """>" & info(1) & "</option>"
        info.movenext
        loop 

        %>
        </select> <br>
        <input id="edit" class="button" type="submit" value="Edit">
      </form>
<%
  '------------------------------------------------------------------
  elseif stage = 3 then
  '------------------------------------------------------------------

    dim title, post, post_id, picture, suburb, postcode, category, u, uid, s_info

    title=Request.Form("title")
    post=Request.Form("post")
    u=Session("username")
    post_id=Request.Form("ProjectsTable.ID")
    picture=Request.Form("image")
    suburb=Request.Form("suburb")
    postcode=Request.Form("postcode")
    category=Request.Form("category")


      '             0       
  sql = "select usertable.id "&_
        "from usertable where username='"&u&"'"
        set info=conn.execute(sql)
        uid = info(0)

   sql="update SuburbTable set suburb='"& suburb & "', postcode=" & postcode & " "&_
       "where projectsTable.ID= "&post_id
       response.write(SQL)
        conn.execute sql

'                0    
  sql = "select id from suburbtable where suburb='" & suburb & "' and postcode=" & postcode & " "
        set s_info=conn.execute(sql)

  sql="update projectsTable set projectName='"& title & "', Description='" & post & "', "&_
      "usernum="& uid & ", categorynum="& category & ", pictureURL='"& picture & "', suburbNum="& s_info(0) & " "&_
      "where projectsTable.ID= "&post_id

      conn.execute sql

       response.write "<p>Post edited.</p>"



  '------------------------------------------------------------------
  end if  ' stage
  '------------------------------------------------------------------

  if stage=3 then
    response.write "<a href=""default.asp"">Show Posts</a>"

    end if
  conn.close 
%>

  </div>

</div>

</div>


<!--#include file="footer.asp"-->
</body>
</html>

1 个答案:

答案 0 :(得分:2)

您的UPDATE中有错误,此语句中没有projectsTable表。我想这是SuburbTable的名字projectsTable_ID(???)而不是projectsTable.ID

的fild

所以看起来应该是这样的:

update SuburbTable set suburb='Kensington', postcode=2033 
where projectsTable_ID= 56

UPD:

我不知道你的桌子是如何相互联系的,但我想通过字段suburbtable.id = projectsTable.SuburbNum。在这种情况下,它应该看起来像:

update SuburbTable set suburb='Kensington', postcode=2033 
where Id=(SELECT SuburbNum from projectsTable where  projectsTable.ID= 56)