ASP进阶之文章在线管理更新(二)

来源:岁月联盟 编辑:zhu 时间:2003-04-14
ASP进阶之文章在线管理更新--文章的添加篇

作者:沙滩小子

上一节已经介绍了关于文章管理的数据库连接,本篇将讲述文章的在线添加,当你找到了一篇很好的资料,并且想尽快放到你的网站上面,如果你首先想到的是快点做好一个页面,并且赶快用FTP把它上传,那么在这里这些都显得没有必要了,在这里你可以通过进入管理页面的添加文章,然后直接把文章粘贴复制过来就可以了,这也是本篇将要讲述的重点--文章的在线添加。

另外通过下面的一步步讲解,相信你可以领会到其中的意义,在这里对HTM代码将不做讲述。

新建一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">
<title>创建文章</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>

<form method="POST" action="savearticle.asp">
<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%">
<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">
</td>
</tr>
<tr>
<td width="15%" align="right" height="30"><b>文章栏目:</b></td>
<td width="85%" height="30">
"利用recordset对象和select打开指定的记录集
<select class="smallSel" name="typeid" size="1">
<%
dim rs,sql,sel
set rs=server.createobject("adodb.recordset")
sql="select * from type"
"设定打开方式为只读
rs.open sql,conn,1,1
"显示该记录集中所有的内容,在这里也就是在下拉菜单中显示文章所属栏目的名称,添加文章的时候要在这里选择其栏目的名称
do while not rs.eof
sel="selected"
response.write "<option " & sel & " value='"+CStr(rs("typeID"))+"' name=typeid>"+rs("type")+"</option>"+chr(13)+chr(10)
"显示了一个记录了以后自动移到下一个记录
rs.movenext
loop
"关闭打开的记录集和数据库连接
rs.close
set rs=nothing
conn.close
%>
</select></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"></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">&nbsp; <input type="reset" value=" 清 除 "
name="cmdcancel" class="buttonface"></p>
</center></div>
</form>
</body>
</html>

至此,我们的文章添加页面就完成了,添加了文章了以后当然还要保存才行啦,所以下节将详细介绍文章保存的详细过程,大家也可以了解在ASP代码中是怎样进行数据库操作的。

转载请注明出处http://asky.on.net.cn