数据库连接代码页
<%
set db=Server.Createobject("ADODB.Connection")
db.Open "ddgfd"
%>
新闻列表页newlist.asp
<!--#include file="connection.asp"-->
<table width="100%" border="1" align="center" cellpadding="4" cellspacing="0" bordercolor="#0099CC" id="AutoNumber2">
<tr bordercolor="#FFFFFF" bgcolor="#0099CC" >
<td height="25" colspan="5" ><div align="center"><font color="#FF0000">动态列表</font></div></td>
</tr>
<tr bordercolor="#FFFFFF" bgcolor="#0099CC" >
<td width="5%" > <p align="center"><font color="#FFFFFF"><b>↓</b></font></td>
<td width="50%" height="30" > <p align="center"><font color="#FFFFFF">标
题</font></td>
<td width="10%" > <div align="center"><font color="#FFFFFF">浏览数</font></div></td>
<td width="15%" > <div align="center"><font color="#FFFFFF">发布者</font></div></td>
<td width="20%" > <p align="center"><font color="#FFFFFF">发布时间</font></td>
</tr>
<%
dim sql,rs
sql="select * from new order by id desc"
set rs=Server.CreateObject("ADODB.Recordset")
rs.Open sql,db,1
if not rs.bof and not rs.eof then
dim page_size
dim page_no
dim page_total
page_size=10
if Request("page_no")="" then
page_no=1
else
page_no=cint(Request("page_no"))
end if
session("page_no")=page_no
rs.pagesize=page_size
page_total=rs.pagecount
rs.absolutepage=page_no
dim i,j
i=0
j=page_size
do while not rs.eof and j>0
i=i+1
j=j-1
%>
<tr>
<td width="5%" > <p align="center"><font color="#FF0000" style="font-size: 6pt">●</font></td>
<td width="50%"><a href="count_hits.asp?id=<%=rs("id")%>"><%=RS("title")%></a></td>
<td width="10%"><%=RS("hits")%></td>
<td width="15%"><%=RS("user_name")%></td>
<td width="20%"><%=rs("submit_date")%></td>
</tr>
<%
rs.movenext
loop
end if
%>
</table></td>
</tr>
</table>
<p align="center"> [本页是第<%=page_no%>/<%=page_total%>页]
[<a href="newlist.asp?page_no=1">首页</a>]
<% if int(page_no)>1 then %>
[<a href="newlist.asp?page_no=<%=cstr(int(page_no)-1)%>">上一页</a>]
<% end if%>
<% if int(page_no)<int(page_total) then %>
[<a href="newlist.asp?page_no=<%=cstr(int(page_no)+1)%>">下一页</a>]
<%end if%>[<a href="newlist.asp?page_no=<%=cstr(int(page_total))%>">末页</a>]
</p></FORM>
</p> </center> </td>
</tr>
</table>
count_hits.asp:浏览新闻时,追回点击率的文件
<!--#include file="connection.asp"-->
<%
dim id
id=request("id")
sql="update new set hits=hits+1 where id=" & id
db.execute(sql)
db.close
response.redirect "newbody.asp?id=" & id
%>
新闻内容显示页newbody.asp
<!--#include file="connection.asp"-->
<%
dim id
id=request("id")
dim sql,rs
sql="select * from new where id =" & id
set rs=db.execute(sql)
%><table border="0" width="500" id="table1" cellspacing="0" cellpadding="0" height="250">
<tr>
<td height="20">
<p align="center"><font color="#FF0000"><%=RS("title")%></font></td>
</tr>
<tr>
<td height=100%>
<div align="center">
<table border="0" width="99%" id="table2" bordercolor="#FFFFFF" bgcolor="#FFFFFF" height="100%">
<tr>
<td><p align="center"><font color="#008000"> 发布时间:<%=rs("submit_date")%>~本文已有<%=RS("hits")%>人次浏览</font></td>
</tr>
<tr>
<td>
<p style="line-height: 200%"> <%=rs("body1")%></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
登录页:静态,表单
<form name="form1" method="post" action="login.asp">
<table width="95%" border="0" align="center" cellpadding="4" cellspacing="0">
<tr>
<td colspan="2"><div align="center">(学生用学号)</div></td>
</tr>
<tr>
<td width="33%"><div align="left">用户或<br>
学号:<br>
</div></td>
<td width="67%"><input name="username" type="text" size="10"></td>
</tr>
<tr>
<td colspan="2"><div align="center"></div></td>
</tr>
<tr>
<td><div align="center">密码:</div></td>
<td><input name="password" type="password" size="9"></td>
</tr>
<tr>
<td><div align="center">类型:</div></td>
<td><div align="center">
<input type="radio" name="s1" value="teacher">
师
<input type="radio" name="s1" value="student">
生</div></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="login" value="登录">
<a href="studentinfo/studentinfo.asp">注册</a></div></td>
</tr>
</table>
</form>
处理登录页信息的页面login.asp
<!--#include file="connection.asp"-->
<%
if Trim(Request("s1"))="teacher" then
strSql ="Select * From admin where LoginID='" & trim(Request.Form("Username")) & "' And password='" & trim(Request.Form("Password")) & "'"
Set rs=db.Execute(strSql)
If Not rs.Bof And Not rs.Eof Then
Session("Name") = RS("Name")
Response.Redirect "sysadmin.asp"
End If
End If
if Trim(Request("s1"))="student" then
strSql2 ="Select * From student where studentid='" & trim(Request.Form("Username")) & "' And password1='" & trim(Request.Form("Password")) & "'"
Set rs2=db.Execute(strSql2)
If Not rs2.Bof And Not rs2.Eof Then
Session("class") = RS2("class")
Session("id") = RS2("id")
Response.Redirect "studentinfo/test.asp"
End If
End If
%>
管理面板页sysadmin.asp
至新闻发布页
至新闻管理列表页
等等
代码略
新闻发布页
<!--#include file="connection.asp"-->
<%
if isempty(Session("name")) then
Response.Redirect "../login.asp"
end if
%>
<table width="80%" align="center" cellpadding="4" cellspacing="1" style="border-collapse: collapse">
<form method="post" action="" name="form1" >
<tr bgcolor="#0099CC">
<td height="25" colspan="2"> <div align="center"><font color="#FFFFFF"><strong>发表动态</strong></font></div></td>
</tr>
<tr>
<td bgcolor="#0099CC"> <div align="center"><font color="#FFFFFF">主题</font></div></td>
<td bgcolor="#F4FAFF"> <input type="text" name="title" size="40">
**</td>
</tr>
<tr>
<td bgcolor="#0099CC"> <div align="center"><font color="#FFFFFF">内容</font></div></td>
<td bgcolor="#F4FAFF"> <textarea name="body1" rows="9" cols="50" wrap="soft"></textarea>
**</td>
</tr>
<tr>
<td bgcolor="#0099CC"> <div align="center"><font color="#FFFFFF">发布者</font></div></td>
<td bgcolor="#F4FAFF"> <p>
<input type="text" name="user_name" size="20">
</p></td>
</tr>
<tr>
<td bordercolor="#0099CC"></td>
<td><input type="submit" value="提交 " size="20"> </td>
</tr>
</form>
<%
if request("title")<>"" then
title=request.form("title")
body1=request.form("body1")
user_name=request.form("user_name")
SQL = "Insert into new(title,body1,user_name,submit_date"
svalues = "values('" & title & "','" &body1& "','" & user_name & "','" & now() & "'"
db.execute(sql)
db.close
Response.Redirect "../index.asp"
end if
%>
</table>
新闻管理列表页newadminlist.asp
至新闻修改页
至新闻删除页
代码略
新闻修改页
<!--#include file="connection.asp"-->
<%
if isempty(Session("name")) then
Response.Redirect "../login.asp"
end if
%>
<%
id=Request.QueryString("id")
strSql ="Select * From new where id=" & id
Set rs=db.Execute(strSql)
%> <table width="80%" align="center" cellpadding="6" cellspacing="1">
<form method="post" action="" name="form1" >
<tr bgcolor="#0099CC">
<td height="25" colspan="2"><div align="center"><font color="#FF0000">动态修改</font></div></td>
</tr>
<tr>
<td bgcolor="#0099CC"> <div align="center"><font color="#FFFFFF">主题</font></div></td>
<td bgcolor="#F4FAFF"> <input type="text" name="title" size="40" value="<%=rs("title")%>">
**</td>
</tr>
<tr>
<td bgcolor="#0099CC"> <div align="center"><font color="#FFFFFF">内容</font></div></td>
<td bgcolor="#F4FAFF"> <textarea name="body1" rows="9" cols="50" wrap="soft"><%=rs("body1")%></textarea></td>
</tr>
<tr>
<td bgcolor="#0099CC"> <div align="center"><font color="#FFFFFF">姓名</font></div></td>
<td bgcolor="#F4FAFF"> <input type="text" name="user_name" size="10" value="<%=rs("user_name")%>">
</td>
</tr>
<tr>
<td></td>
<td><input name="submit" type="submit" value="修改 " size="20"> </td>
</tr>
</form>
<%
If Request("body1")<>"" Then
Dim title,body1,user_name
title=Request("title")
body1=Request("body1")
user_name=Request("user_name")
strSql="update new set user_name='" & user_name & "',title='" & title & "',body1='" & body1 & "' where id=" & id
db.Execute(strSql)
Response.Redirect "newadminlist.asp"
Else
Response.Write ""
End If
%>
</table>
删除新闻页
<!--#include file="connection.asp"-->
<%
if isempty(Session("name")) then
Response.Redirect "../login.asp"
end if
%>
<%
dim sql,id
id=request.querystring("id")
sql="delete from new where id =" & id
db.Execute(sql)
db.close
Response.Redirect "newadminlist.asp"
%>