急!修改ASP文章内容时,当提交的时候,却变成了添加一条记录!请大家指教

weihanmingwhmwhm 2012-08-07 08:43:25
<!--#include file="conn.asp"-->
<!--#include file="admin.asp"-->

<%
title=server.htmlencode(Trim(Request("id")))
Content=Trim(Request("Content"))
BigClassName=request("BigClassName")
client=request("client")
prosize=request("prosize")
prodic=request("prodic")
compyear=request("compyear")
SmallClassName=request("SmallClassName")
%>
<%if Request.QueryString("mark")="southidc" then%>
<%
If Content="" Then
response.write "SORRY <br>"
response.write "内容不能为空!!<a href=""javascript:history.go(-1)"">返回重输</a>"
response.end
end if

Set rs = Server.CreateObject("ADODB.Recordset")
if title="" then
sql="select * from Procase"
else
sql="select * from Procase where id="&title
end if
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,3
response.Write(title)
if title="" then
rs.addnew
else
end if
rs("SmallClassName")=SmallClassName
rs("BigClassName")=BigClassName
rs("title")=request.Form("arttitle")
rs("Content")=Content
rs("client")=client
rs("prosize")=prosize
rs("compyear")=compyear
rs("prodic")=prodic
rs("firstImageName")= trim(Request.form("img"))
rs.update
rs.close
response.redirect "News_Manage.asp"
end if
%>
<%
dim rs
dim sql
dim count
set rs=server.createobject("adodb.recordset")
sql = "select * from SmallClass_New order by SmallClassID asc"
rs.open sql,conn,1,1
%>
<script language = "JavaScript">
var onecount;
subcat = new Array();
<%
count = 0
do while not rs.eof
%>
subcat[<%=count%>] = new Array("<%= trim(rs("SmallClassName"))%>","<%= trim(rs("BigClassName"))%>","<%= trim(rs("SmallClassName"))%>");

<%
count = count + 1
rs.movenext
loop
rs.close
%>


onecount=<%=count%>;

function changelocation(locationid)
{
document.myform.SmallClassName.length = 1;
var locationid=locationid;
var i;
for (i=0;i < onecount; i++)
{
if (subcat[i][1] == locationid)
{
document.myform.SmallClassName.options[document.myform.SmallClassName.length] = new Option(subcat[i][0], subcat[i][2]);
}
}
}
function CheckForm()
{
if (editor.EditMode.checked==true)
document.myform.Content.value=editor.HtmlEdit.document.body.innerText;
else
document.myform.Content.value=editor.HtmlEdit.document.body.innerHTML;

if (document.myform.Content.value=="")
{
alert("内容不能为空!");
editor.HtmlEdit.focus();
return false;
}
return true;
}
</script>
<%
mainContent=""
Set rs1 = Server.CreateObject("ADODB.Recordset")
sql1="select * from Procase where id="&title
Set rs1= Server.CreateObject("ADODB.Recordset")
rs1.open sql1,conn,1,3
if rs1.bof and rs1.eof then
else
mainContent = rs1("Content")
end if
%>
<!-- #include file="Inc/Head.asp" -->
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="top"> <br> <br> <table width="790" border="0" cellpadding="2" cellspacing="1" bgcolor="#CCFFFF" class="table_southidc"><form method="post" name="myform" action="ArtModify.asp?mark=southidc&ArticleID=<%=Request("ArticleID")%>" onSubmit="return CheckForm();">

<tr>
<td width="159" height="12" align="right" class="back_southidc">标题:</td>
<td width="620" class="back_southidc"><input name="arttitle" value="<%=rs1("title")%>" size="50" /></td>
</tr>
<tr>
<td height="0" align="right"><font color="#FF0000">*</font>类别:</td>
<td valign="top">
<%
sql = "select * from BigClass_New"
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.write "请先添加栏目。"
else
%> <select name="BigClassName" onChange="changelocation(document.myform.BigClassName.options[document.myform.BigClassName.selectedIndex].value)" size="1">
<%
do while not rs.eof
%>
<option value="<%=trim(rs("BigClassName"))%>" selected <% if rs("BigClassName")=rs1("BigClassName") then response.Write("selected") end if%>><%=trim(rs("BigClassName"))%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select> <select name="SmallClassName">
<option value="" selected <%if rso("SmallClassName")="" then response.write "selected"%>>不指定小类</option>
<%
sql="select * from SmallClass_New where BigClassName='" & rs1("BigClassName") & "'"
rs.open sql,conn,1,1
if not(rs.eof and rs.bof) then
do while not rs.eof %>
<option value="<%=rs("SmallClassName")%>" <% if rs("SmallClassName")=rs1("SmallClassName") then response.Write("selected") end if%>><%=rs("SmallClassName")%></option>
<%
rs.movenext
loop
end if
rs.close
%>
</select>





</td>
</tr>
<tr>
<td colspan="2"><div align="center">
<table width="100%" border="0" cellspacing="1" cellpadding="0">

<tr>
<td width="20%" height="22" align="right" valign="top"><textarea name="Content" style="display:none"><%=mainContent%></textarea>
内容:</td>
<td width="80%" align="center">
<iframe id="editor" src="../ArtMagEditor.asp?mytitle=<%=Request("id")%>" frameborder=1 scrolling=no width="620" height="405"></iframe></td>
</tr>
<tr bgcolor="#ECF5FF">
<td height="12">图片地址:</td>
<td><input name="img" type="text" id="img" value="<%=rs1("FirstImageName")%>" size="30" maxlength="50">
<br />
<iframe style="top:2px" ID="UploadFiles" src="../upload_Photo.asp?PhotoUrlID=5" frameborder=0 scrolling=no width="300" height="25"></iframe></td>
</tr>

<tr>
<td height="25" colspan="2">
<div align="center">
<input name="submit" type="submit" value="确定">
 
<input name="reset" type="reset" value="取消">

</div></td>
</tr>
</table>
</div></td>
</tr> </form>
</table>
<br> </td>
</tr>
</table>
<%rs1.close%>
<!-- #include file="Inc/Foot.asp" -->
...全文
127 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
Dogfish 2012-08-10
  • 打赏
  • 举报
回复
title=server.htmlencode(Trim(Request("id")))
这里的id是否一个数字?
weihanmingwhmwhm 2012-08-10
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 的回复:]

看来在这说不清楚了。Q我348736477
[/Quote]

好的,谢谢
scscms太阳光 2012-08-10
  • 打赏
  • 举报
回复
看来在这说不清楚了。Q我348736477
weihanmingwhmwhm 2012-08-10
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]

title=server.htmlencode(Trim(Request("id")))
这里的id是否一个数字?
[/Quote]

title=server.htmlencode(Trim(Request("id"))) 这个是ID是定义文章标题的,我刚试了
weihanmingwhmwhm 2012-08-10
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]

title=server.htmlencode(Trim(Request("id")))
这里的id是否一个数字?
[/Quote]

不明白
weihanmingwhmwhm 2012-08-10
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 的回复:]

大姐看看上面的回复吧,已经提醒你少了 input name=id
[/Quote]

哥,你直接写出来,放到那里,我试了,好像不行。不是知道位置对不对
scscms太阳光 2012-08-10
  • 打赏
  • 举报
回复
大姐看看上面的回复吧,已经提醒你少了 input name=id
weihanmingwhmwhm 2012-08-10
  • 打赏
  • 举报
回复
1楼 你的问题就出现在缺少id的标签:<input type="hidden" name="id" value="<%=Rs("id")%>" /> 把它加到form标签内即可

<input name="id" type="hidden" value="<%=rs1("id")%>" />

这样就可以了,与你说的差不多,之前测试时少了rs1.谢谢,以后有空多多交流,这个号我经常上线的
weihanmingwhmwhm 2012-08-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

你的问题就出现在缺少id的标签:<input type="hidden" name="id" value="<%=Rs("id")%>" /> 把它加到form标签内即可
[/Quote]

<input name="id" type="hidden" value="<%=rs1("id")%>" /> 这样就可以了,与你说的差不多,之前测试时少了rs1.谢谢,以后有空多多交流,这个号我经常上线的
weihanmingwhmwhm 2012-08-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

你的问题就出现在缺少id的标签:<input type="hidden" name="id" value="<%=Rs("id")%>" /> 把它加到form标签内即可
[/Quote]

<input name="id" type="hidden" value="<%=rs1("id")%>" />

这样写就对了,与你这们差不多了。上次测试时没有写rs1。谢谢,这个号我经常在线的,有空多多交流。
  • 打赏
  • 举报
回复
还有一点,就是title=server.htmlencode(Trim(Request("id")))
这个这里,id是文章的ID,那么应该是数字,既然是数字,不要用server.htmlencode这个去处理,应该用数字的相关函数处理
  • 打赏
  • 举报
回复
title=server.htmlencode(Trim(Request("id")))
你注意看你的哲理
你的title是经过这个参数ID才得到值的
所以,ID如果没有值,那么title没有值
那么你下面的
if title="" then
rs.addnew
else
end if

哲理的title永远都执行第一句,也就是永远执行rs.addnew这个了
所以你要保证id有值,才能保证title有值,才能区分增加和修改
scscms太阳光 2012-08-09
  • 打赏
  • 举报
回复
if title="" then
rs.addnew
else
end if

rs.addnew 是新添加,但有条件的呀。问题就是 title为空成立,也就是id获取不到,所以说是缺少input name="id"
ww111222 2012-08-09
  • 打赏
  • 举报
回复


rs. addnew 是 增加一条新记录。


错在这里了。
weihanmingwhmwhm 2012-08-09
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

if title="" then
rs.addnew
else
end if

应该是这部分出了问题了
检查 一下吧
[/Quote]

除掉rs.addnew ,然后点修改时,是不会添加记录了,但修改也不成功。奇怪
weihanmingwhmwhm 2012-08-09
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]
rs. addnew 是 增加一条新记录。


错在这里了。
[/Quote]

是不是把rs.addnew 记录删了
weihanmingwhmwhm 2012-08-09
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]

VB code
if title="" then
rs.addnew
else
end if

rs.addnew 是新添加,但有条件的呀。问题就是 title为空成立,也就是id获取不到,所以说是缺少input name="id"
[/Quote]

谢谢,该如何解决呢?能不能直接写出解决代码
  • 打赏
  • 举报
回复
if title="" then
rs.addnew
else
end if

应该是这部分出了问题了
检查 一下吧
  • 打赏
  • 举报
回复
if title="" then
rs.addnew
else
end if

应该是这部分出了问题了
检查 一下吧
scscms太阳光 2012-08-07
  • 打赏
  • 举报
回复
你的问题就出现在缺少id的标签:<input type="hidden" name="id" value="<%=Rs("id")%>" /> 把它加到form标签内即可

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧