一个简单的留言板程序

  说明:《网络程序设计-ASP》(蔡翠平主编、尚俊杰编著,清华大学出版社、北方交通大学出版社),第8章习题的实践题第4题:

  开发一个简单的留言板程序

  留言板有多种类型。如,
  1、留言后,只有网站管理员才能查看。
  2、留言后,其他访问者也能查看。
  下面的网页代码,是笔者编写的,《在线调查》的网页代码,也是一种留言板。既有让留言者选择的项目,也有自由留言的项目。留言(在线调查)提交后,普通访问者不能查看。
  在线调查由两部分组成,一是访问者提交表单的网页;二是将访问提交的信息添加到数据库之是的网页。

  下面是访问提交表单的网页(界面)代码。

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>在线调查</title>
<link href="../css-1.css" rel="stylesheet" type="text/css">
</head>
<%
dim IP
IP_address=Request.ServerVariables("REMOTE_ADDR")
%>
<h1 align="center">在线调查   </h1>
<p>  说明:为了有针对性地添加网友们感兴趣的内容,特作此调查。<br>
  望将下面三个问题的答案,填写完整。谢谢合作! </p>
<table>
<tr>
<td><form name="form1" method="post" action="add.asp">
<table width="750" border="1" cellspacing="0" bordercolor="#000000" >
<tr>
<td colspan="4" class="base-4">一、您是通过什么途径访问(了解)的</td>
<td width="20%">&nbsp;</td>
</tr>
<tr >
<td width="20%" class="base-3"> <input type="radio" name="a1" value="搜索引擎">
搜索引擎 </td>
<td width="20%" class="base-3"> <input type="radio" name="a1" value="其他网站">
其他网站</td>
<td width="20%" class="base-3"> <input type="radio" name="a1" value="他人介绍">
他人介绍</td>
<td width="20%" class="base-3"> <input type="radio" name="a1" value="其他途径">
其他途径</td>
<td width="20%"> </td>
</tr>
<tr>
<td colspan="4" class="base-4">二、您的年龄</td>
<td width="20%">&nbsp;</td>
</tr>
<tr >
<td width="20%" class="base-3"> <input type="radio" name="a2" value="18">
<20岁</td>
<td width="20%" class="base-3"> <input type="radio" name="a2" value="20">
20-29岁</td>
<td width="20%" class="base-3"> <input type="radio" name="a2" value="30">
30-44岁</td>
<td width="20%" class="base-3"> <input type="radio" name="a2" value="45">
45-60岁</td>
<td width="20%" class="base-3"> <input type="radio" name="a2" value="60">
>60岁</td>
</tr>
<tr>
<td colspan="4" class="base-4">三、对本网站的意见、建议</td>
<td>&nbsp;</td>
</tr>
<tr >
<td colspan="4" class="base-3"> <textarea name="c1" cols="80" rows="5"></textarea>
</td>
<td class="base-3">&nbsp; </td>
</tr>
<tr>
<td width="20%">&nbsp;</td>
<td width="20%"><div align="center">
<input type="submit" name="Submit" value="提交">
</div></td>
<td width="20%">&nbsp;</td>
<td width="20%"><div align="center">
<input type="reset" name="Submit2" value="重填">
</div></td>
<td width="20%">&nbsp;</td>
</tr>
</table>
</form></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>

  下面是将表单中内容添加到数据库中的网页代码。

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>调查结果</title>
</head>
<body>
<h2 align="center">
<%
dim a1,a2,c1
a1=Request.Form("a1")
a2=Request.Form("a2")
c1=Request.Form("c1")
if a1="" or a2="" or c1="" then
Response.Write "信息填写不完全!<br>"
Response.Write "<a href='index.asp' >重填</a>"
Response.End
end if
dim db,strsql,URL
URL=Request.ServerVariables("REMOTE_ADDR")
set db=server.createObject("ADODB.Connection")
dbpath=server.mappath("research.asa")
db.open "driver={Microsoft Access Driver (*.mdb)};dbq="& dbpathstrsql="insert into no1(path,age,interest,ip_address,submit_date) Values('"& a1 & "', '"& a2 &"', '" & c1 &"','"& URL & "', #" & now() & "#)"
db.Execute(strsql)
%>
</h2>
<h2 align="center" >
<%
Response.Write "谢谢!"
%>
</h2>
<table width="121" height="35" border="0" align="center" cellpadding="0" cellspacing="0">
<tr align="middle">
<td><script language="JavaScript">
function shutwin(){
window.close();
return;}
</script> <a href="javascript:shutwin();">关闭本窗口</a></td>
</tr>
</table>
<p align="center" >&nbsp;</p>
<p>
</body>
</html>


主页                                  {其它

   

《花桥电脑书斋》-邱泳昱的个人主页
如需转载望能征求本人意见