日期:2011-01-08  浏览次数:20957 次

 上一节已经介绍了关于文章管理的数据库连接,本篇将讲述文章的在线添加,当你找到了一篇很好的资料,并且想尽快放到你的网站上面,如果你首先想到的是快点做好一个页面,并且赶快用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>