[此贴子已经被作者于2006-3-18 17:28:09编辑过]
下个论坛去研究研究~~
给个留言本你看一下,一个页面:
post.asp
----------------------------------------------------------------------------------------------
<% '数据库连接
dim conn
dim connstr
on error resume next
connstr="DBQ="+server.mappath("bbs.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
Sub rsclose()
rs.close()
set rs=nothing
End Sub
Sub connclose()
conn.close()
set conn=nothing
End Sub
%>
<%
act=Request.Querystring("act")
posters=Replace(Request.Form("posters"),"'","''")
titles=Replace(Request.Form("titles"),"'","''")
artic=Replace(Request.Form("artic"),"'","''")
artic=replace(artic,vbcrlf,"<br>")
artic=replace(artic," "," ")
postime=now()
overview="1"
if act="save" then
if posters="" then
%>
<script>alert('姓名不能为空!');history.back();</Script>
<%else
if titles="" then
%>
<script>alert('标题不能为空!');history.back();</Script>
<%else
if artic="" then
%>
<script>alert('请先填写留言内容!');history.back();</Script>
<%else
saveartic()
end if
end if
end if
else
if act="nowpost" then
poster()
else
view()
end if
end if
%>
<%'生成留言表单
function poster()
response.write "<form method='POST' action='"&url&"?act=save'>"
response.write "<table width='400' border='1' cellpadding='0' cellspacing='0' bordercolor='#000000' style='border-collapse:collapse'><tr>"
response.write "<td bgcolor='#6699CC'><div align='center'><font color='#FFFFFF' size='3'>添加记录</font></div></td><tr>"
response.write"<td height='112'><table width='400' border='0' cellpadding='0' cellspacing='0' bgcolor='#CCCCFF'><tr>"
response.write"<td width='14%' height='41'><div align='center'><font size='2'>姓名:</font></div></td>"
response.write"<td width='86%' height='41'><input type='text' name='posters' size='10'></td><tr>"
response.write"<td height='39'><p align='center'><font size='2'>标题:</font></p></td>"
response.write"<td height='39'><input type='text' name='titles' size='30'></td></tr><tr>"
response.write"<td height='41'><div align='center'><font size='2'>留言:</font></div></td>"
response.write"<td height='41'><textarea name='artic' cols='30' rows='5'></textarea></td><tr>"
response.write"<td height='10'></td>"
response.write"</table></td>"
response.write"</table>"
response.write"<p align='left'> <input type='submit' value='提交' name='B1'> <input type='reset' value='清空' name='B2'></p>"
response.write"</form>"
end function
'保存记录函数
function saveartic()
set rs=conn.execute("insert into liuyian(posters,titles,artic,postime,overview)values('"&posters&"','"&titles&"','"&artic&"','"&postime&"','"&overview&"')")
response.write "<script>alert('留言成功!');</Script>"
response.write "<OBJECT id=hh2 classid='clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11'><PARAM NAME='Command' VALUE='Close'></OBJECT>"
response.write "<input type=button value=关闭窗口 onclick=hh2.Click()>"
end function
'显示记录函数
function view() %>
----------------------------------------<BR>
<%
set rs=conn.execute("select*from liuyian order by id DESC")
do while not rs.eof
%>
<%=rs("posters")%> ----- <b><%=rs("titles")%></b><br>
<%=rs("artic")%><br>
<font size="2" color="#ff0000"><%=rs("postime")%></font><br>
-----------------------------------------<br>
<%
rs.movenext
loop
rs.close
set rs=nothing
%>
<a onclick=window.open("<%'&url&'%>?act=nowpost","adduserid","width=340,height=250") style="cursor:hand">我要留言</a>
<%
end function
%>
--------------------------------------------------------------------------------------------
数据库bbs.mdb中一个表:
liuyian
id posters titles artic postime overview
功能还没写完
if act="save" then
if posters="" then
%>
<script>alert('姓名不能为空!');history.back();</Script>
<%else
if titles="" then
%>
<script>alert('标题不能为空!');history.back();</Script>
<%else
if artic="" then
%>
<script>alert('请先填写留言内容!');history.back();</Script>
<%else
saveartic()
end if
end if
end if
else
if act="nowpost" then
poster()
else
view()
end if
end if
便是!