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