ASP进阶之文章在线管理更新--文章的添加篇
作者:沙滩小子
上一节已经介绍了关于文章管理的数据库连接,本篇将讲述文章的在线添加,当你找到了一篇很好的资料,并且想尽快放到你的网站上面,如果你首先想到的是快点做好一个页面,并且赶快用FTP把它上传,那么在这里这些都显得没有必要了,在这里你可以通过进入管理页面的添加文章,然后直接把文章粘贴复制过来就可以了,这也是本篇将要讲述的重点--文章的在线添加。
另外通过下面的一步步讲解,相信你可以领会到其中的意义,在这里对HTM代码将不做讲述。
新建一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<title>创建文章</title>
6<link href="style.css" rel="stylesheet" type="text/css"/>
7</head>
8<body>
9<form action="savearticle.asp" method="POST">
10<div align="center"><center><table border="1" bordercolordark="#FFFFFF" bordercolorlight="#000000" cellpadding="0" cellspacing="0" width="80%">
11<tr>
12<td bgcolor="#D0D0D0" height="20" width="100%"><div align="center"><center><p><b>添 加 文 章</b></p></center></div></td>
13</tr>
14<tr align="center">
15<td width="100%"><table border="0" cellspacing="1" width="100%">
16<tr>
17<td align="right" height="30" width="15%"><b>文章标题:</b></td>
18<td height="30" width="85%">
19"这里输入文章标题信息
20<input class="smallinput" maxlength="100" name="txttitle" size="70" type="text"/>
21</td>
22</tr>
23<tr>
24<td align="right" height="30" width="15%"><b>文章栏目:</b></td>
25<td height="30" width="85%">
26"利用recordset对象和select打开指定的记录集
27<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 "="" &="" name="typeid" sel="" value='"+CStr(rs("typeID"))+"'>"+rs("type")+"</option>"+chr(13)+chr(10)
"显示了一个记录了以后自动移到下一个记录
rs.movenext
loop
"关闭打开的记录集和数据库连接
rs.close
set rs=nothing
conn.close
1</select></td>
2</tr>
3<tr>
4<td align="right" valign="top" width="15%"><b>文章内容:</b></td>
5<td width="85%">
6"文章内容添加区
7<textarea class="smallarea" cols="70" name="txtcontent" rows="15"></textarea></td>
8</tr>
9<tr>
10<td align="right" height="20" valign="top" width="15%"></td>
11<td width="85%"></td>
12</tr>
13</table>
14</td>
15</tr>
16</table>
17</center></div><div align="center"><center><p><input class="buttonface" name="cmdok" type="submit" value=" 添 加 "/> <input class="buttonface" name="cmdcancel" type="reset" value=" 清 除 "/></p>
18</center></div>
19</form>
20</body>
21</html>
至此,我们的文章添加页面就完成了,添加了文章了以后当然还要保存才行啦,所以下节将详细介绍文章保存的详细过程,大家也可以了解在ASP代码中是怎样进行数据库操作的。