| 
 | 
 
          
            | 
                 
                  | ASP进阶之文章在线管理更新(十一) |   
                  | 〖编辑:Cloudy | 浏览:人次〗 |  
                 
                  | ASP进阶之文章在线管理更新--文章修改篇 
 作者:沙滩小子
 
 上一节我们讲了文章的在线删除的具体实现方法,在这里我将为大家介绍关于文章管理系统的在线修改。在本系统中,提供在线修改是一项必不可少的内容,因为当大家在网上更新文章的时候,总会碰上这样那样的问题,一个不小心就会造成添加的失误,有时候是内容不全,也有可能是文章的栏目原来添加的时候选错了,同时也就是这样那样的错误才显得这个程序的必要性。
 
 文章的在线修改保存的程序其实和文章的添加和保存程序差不多,只是这里是对数据库进行更新,而文章添加则是对数据库进行新增记录,不过从总体上来说还是差不多的,所以这里我只是对那些两个程序的不同点进行注解,其他要是大家有什么不明白的地方可以看看本专题的第二、三节,下面就来为大家介绍实现这一功能的过程:
 
 (1).文件edit.asp,这个文件没有什么好讲的了,因为基本上和本系统的addarticle.asp程序是相同的,只有在文章标题和文章内容部分取了相应的数据库内容,以方便大家参考修改。
 <!--#include file="conn.asp"-->
 <%
 if request.cookies("adminok")="" then
 response.redirect "login.asp"
 end if
 %>
 <html>
 
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
 <meta name="GENERATOR" content="Microsoft FrontPage 3.0">
 <link rel="stylesheet" type="text/css" href="style.css">
 <title>修改文章</title>
 </head>
 
 <body>
 
 <form method="POST" action="saveedit.asp?id=<%=request("id")%>">
 <div align="center"><center><table border="1" cellspacing="0" width="80%" bordercolorlight="#000000" bordercolordark="#FFFFFF" cellpadding="0">
 <tr>
 <td width="100%" bgcolor="#D0D0D0" height="20"><div align="center"><center><p><b>修 改 文 章</b></td>
 </tr>
 <tr align="center">
 <td width="100%"><table border="0" cellspacing="1" width="100%">
 <%
 dim sql
 dim rs
 sql="select * from article where articleid="&request("id")
 set rs=server.createobject("adodb.recordset")
 rs.open sql,conn,1,1
 %>
 <tr>
 <td width="15%" align="right" height="30"><b>文章标题:</b></td>
 <td width="85%" height="30"><input type="text" name="txttitle" size="70"
 class="smallinput" maxlength="100" value="<%=rs("title")%>"></td>
 </tr>
 <tr>
 <td width="15%" align="right" valign="top"><b>文章内容:</b></td>
 <td width="85%"><textarea rows="15" name="txtcontent" cols="70" class="smallarea"><%content=replace(rs("content"),"<br>",chr(13))
 content=replace(content," "," ")
 response.write content%></textarea></td>
 </tr>
 <tr>
 <td width="15%" align="right" valign="top" height="20"></td>
 <td width="85%"></td>
 </tr>
 </table>
 </td>
 </tr>
 </table>
 </center></div><div align="center"><center><p><input type="submit" value=" 修 改 "
 name="cmdok" class="buttonface">  <input type="reset" value=" 复 原 "
 name="cmdcancel" class="buttonface"></p>
 </center></div>
 </form>
 </body>
 </html>
 <%
 rs.close
 set rs=nothing
 conn.close
 set conn=nothing
 %>
 
 (2).文件SaveEdit.asp,这里的保存修改文件也和添加文章中的保存差不多,只不过它是对数据库进行更新,而添加文章中的保存是对数据库进行添加新记录操作。
 
 "打开数据库连接
 <!--#include file="conn.asp"-->
 "打开对文章内容的代码进行转化文件
 <!--#include file="inc/articlechar.inc"-->
 <%
 if request.cookies("adminok")="" then
 response.redirect "login.asp"
 end if
 %>
 <%
 dim typename
 dim title
 dim content
 dim sql
 dim rs
 dim articleid
 title=htmlencode2(request.form("txttitle"))
 content=htmlencode2(request.form("txtcontent"))
 articleid=request("id")
 "打开数据库指定记录集中的指定记录,并对其进行更新操作
 set rs=server.createobject("adodb.recordset")
 sql="select * from article where articleid="&articleid
 rs.open sql,conn,3,3
 "请注意:这里并没有加入rs.addnew表示只是对数据库的指定记录进行更新操作,而没有添加新的记录
 rs("title")=title
 rs("content")=content
 rs("dateandtime")=date()
 "更新数据库
 rs.update
 "关闭数据库连接
 rs.close
 set rs=noting
 conn.close
 set conn=nothing
 "对数据库更新完毕后,把页面重新转向文章管理页面manage.asp
 response.redirect "manage.asp"
 %>
 
 写到这里,我们的文章在线管理系统就算基本完成了,我也相信大家经过这些时间的学习已经掌握了本系统的基本原理,也可以通过本专题建立自己的文章在线管理系统,不过在最后我还要向大家介绍本人对文章管理系统新添加的一段程序,也就是对管理员的名字和密码、文章栏目的在线修改删除添加程序,以使本系统更加完善,请看下一篇管理员&栏目管理篇.
 
 转载请注明出处http://asky.on.net.cn
 |   
                  | 录入时间:2006-06-04 18:54:11    [打印本页] 
                    [关闭窗口] 
                    [返回顶部]
 |  
                
                  | 特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。 |  |  
 |