如何用ASP和SQL创建一个留言板 20
1个回答
展开全部
这个是简单的留言板代码,数据库就要你自己设计了,网页代码是:
<html>
<head>
<style>
<!--
A:link,
A:visited { text-decoration: none; color:#008040 }
A:hover { text-decoration: underline; color: #ff0000 }
-->
</style>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=gb_2312-80">
<title>留言薄</title>
</head>
<%@ language="vbscript"%>
<%
Function Deal(exp1)
dim exp2
exp2=Replace(exp1,"<","<")
exp2=Replace(exp2,">",">")
exp2=Replace(exp2,"'","''")
exp2=Replace(exp2,Chr(13),"<br>")
Deal=exp2
End Function
'建立与数据库的连接
Set Conn=Server.CreateObject("ADODB.Connection")
Connstr="DBQ="+server.mappath("guestbook.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;ImplicitCommitSync=Yes;MaxBufferSize=512;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UserCommitSync=Yes;"
Conn.Open connstr
If Request("task")="insert" then
If Request("xm")="" then
xm="不告诉你"
else
xm=Request("xm")
xm=Deal(xm)
end if
if request("email")="" then
email="还没有那"
email=Deal(email)
else
email=Request("email")
end if
if request("url")="" then
url="没有"
else
url=Request("url")
url=Deal(url)
end if
sj = Date()
sj = sj & " " & Hour(Time()) & ":" & Minute(Time())
If Request("ly")="" then
Response.write("请输入留言!")
Response.end
else
ly=Request("ly")
ly=Deal(ly)
end if
sql="INSERT INTO lyb (ip,xm,url,email,sj,ly) VALUES ('"
sql=sql & Request("REMOTE_ADDR") & "','" & xm & "','" & url & "','" & email & "','" & sj & "','" & ly & "')"
conn.execute(sql)
end if
set rs=server.createobject("adodb.recordset")
on error resume next
rs.open "select * from lyb order by sj DESC",conn,1,1
rs.pagesize=15
rs.AbsolutePage =1
if request("page")<>"" then rs.AbsolutePage =Request("page")
RowCount =rs.pagesize
%>
<body topmargin="0" leftmargin="2" text="#008000">
<p><font face="楷体_GB2312" color="#008000"><big><big><big><strong>
留言薄
</strong></big></big></big></font></p>
<form METHOD="POST" action="<%=Request("SCRIPT_NAME")%>">
<input type="hidden" name="task" value="insert"><p>
姓名:<input TYPE="text" SIZE="20" NAME="xm"><br>
邮件:<input TYPE="text" SIZE="20" NAME="email"><br>
主页:<input TYPE="text" SIZE="20" NAME="url"><br>
留言:<br>
<textarea ROWS="5" COLS="60" NAME="ly">
</textarea></p>
<p><input TYPE="submit" VALUE="记入留言薄" NAME="B1">
<input TYPE="reset" VALUE="重写" NAME="B2"></p>
</form>
<hr>
<%
if not rs.eof then
Do While Not RS.EOF and RowCount>0
%>
<p>日期:<%=rs("sj")%><br>
<%
if rs("xm")<>"" then
%>
姓名:<%=rs("xm")%><br>
<%
end if
if rs("url")<>"" then
%>
主页:<a href="<%=rs("url")%>"><%=rs("url")%></a><br>
<%
end if
if rs("email")<>"" then
%>
邮件:<a href="mailto:<%=rs("email")%>"><%=rs("email")%></a><br>
<%
end if
%>
留言:<br>
<%=rs("ly")%></p>
<hr>
<%
RowCount = RowCount - 1
rs.movenext
loop
else
response.write("留言本空")
end if
%>
<%
if rs.pagecount>1 then
%>
<table border="0">
<tr>
<td>留言分页</td>
<%
for i=1 to rs.pagecount
%>
<td>
<a href="<%=Request("Script_Name")%>?page=<%=i%>"><b><%=i%></b></a>
</td>
<%next%>
</tr>
</table>
<%
end if
rs.close
Set rs=nothing
conn.close
Set conn=nothing
%>
</body>
</html>
<html>
<head>
<style>
<!--
A:link,
A:visited { text-decoration: none; color:#008040 }
A:hover { text-decoration: underline; color: #ff0000 }
-->
</style>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=gb_2312-80">
<title>留言薄</title>
</head>
<%@ language="vbscript"%>
<%
Function Deal(exp1)
dim exp2
exp2=Replace(exp1,"<","<")
exp2=Replace(exp2,">",">")
exp2=Replace(exp2,"'","''")
exp2=Replace(exp2,Chr(13),"<br>")
Deal=exp2
End Function
'建立与数据库的连接
Set Conn=Server.CreateObject("ADODB.Connection")
Connstr="DBQ="+server.mappath("guestbook.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;ImplicitCommitSync=Yes;MaxBufferSize=512;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UserCommitSync=Yes;"
Conn.Open connstr
If Request("task")="insert" then
If Request("xm")="" then
xm="不告诉你"
else
xm=Request("xm")
xm=Deal(xm)
end if
if request("email")="" then
email="还没有那"
email=Deal(email)
else
email=Request("email")
end if
if request("url")="" then
url="没有"
else
url=Request("url")
url=Deal(url)
end if
sj = Date()
sj = sj & " " & Hour(Time()) & ":" & Minute(Time())
If Request("ly")="" then
Response.write("请输入留言!")
Response.end
else
ly=Request("ly")
ly=Deal(ly)
end if
sql="INSERT INTO lyb (ip,xm,url,email,sj,ly) VALUES ('"
sql=sql & Request("REMOTE_ADDR") & "','" & xm & "','" & url & "','" & email & "','" & sj & "','" & ly & "')"
conn.execute(sql)
end if
set rs=server.createobject("adodb.recordset")
on error resume next
rs.open "select * from lyb order by sj DESC",conn,1,1
rs.pagesize=15
rs.AbsolutePage =1
if request("page")<>"" then rs.AbsolutePage =Request("page")
RowCount =rs.pagesize
%>
<body topmargin="0" leftmargin="2" text="#008000">
<p><font face="楷体_GB2312" color="#008000"><big><big><big><strong>
留言薄
</strong></big></big></big></font></p>
<form METHOD="POST" action="<%=Request("SCRIPT_NAME")%>">
<input type="hidden" name="task" value="insert"><p>
姓名:<input TYPE="text" SIZE="20" NAME="xm"><br>
邮件:<input TYPE="text" SIZE="20" NAME="email"><br>
主页:<input TYPE="text" SIZE="20" NAME="url"><br>
留言:<br>
<textarea ROWS="5" COLS="60" NAME="ly">
</textarea></p>
<p><input TYPE="submit" VALUE="记入留言薄" NAME="B1">
<input TYPE="reset" VALUE="重写" NAME="B2"></p>
</form>
<hr>
<%
if not rs.eof then
Do While Not RS.EOF and RowCount>0
%>
<p>日期:<%=rs("sj")%><br>
<%
if rs("xm")<>"" then
%>
姓名:<%=rs("xm")%><br>
<%
end if
if rs("url")<>"" then
%>
主页:<a href="<%=rs("url")%>"><%=rs("url")%></a><br>
<%
end if
if rs("email")<>"" then
%>
邮件:<a href="mailto:<%=rs("email")%>"><%=rs("email")%></a><br>
<%
end if
%>
留言:<br>
<%=rs("ly")%></p>
<hr>
<%
RowCount = RowCount - 1
rs.movenext
loop
else
response.write("留言本空")
end if
%>
<%
if rs.pagecount>1 then
%>
<table border="0">
<tr>
<td>留言分页</td>
<%
for i=1 to rs.pagecount
%>
<td>
<a href="<%=Request("Script_Name")%>?page=<%=i%>"><b><%=i%></b></a>
</td>
<%next%>
</tr>
</table>
<%
end if
rs.close
Set rs=nothing
conn.close
Set conn=nothing
%>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询