count.asp
' 计数器的核心程序.
<%
Set conn = Server.CreateObject("ADODB.Connection")
dbpath=server.MapPath("count.mdb")
conn.open "driver={Microsoft Access Driver (*.mdb)};dbq="&DbPath
user=Request.QueryString("user")
sql="update counttable set curvalue=curvalue+1 where user='"&user&"'"
' 计数值加1.
conn.Execute sql
sql="select curvalue from counttable where user='"&user&"'"
set rs=conn.Execute(sql)
function chgimg(curvalue)
dim s,i,g
s=cstr(curvalue)
for i=1 to len(s)
' 定义chgimg函数,将计数值用图形表示.
g=g & "<img src=1/" & mid(s,i,1) & ".gif align=bottom>"
' 在正式使用计数器时,图片的路径要用实际路径.
next
chgimg=g
end function
toimg=chgimg(rs("curvalue"))
toimg="document.write(" & "'" & toimg & "')"
' 调用chgimg函数传入计数器值.
Response.Write(toimg)
' 输出.
rs.close
set rs=nothing
conn.Close
set conn=nothing
%>
get.htm
' 申请表单.
<form method="POST" action="getcl.asp">
<p>用户名<input type="text" name="user" size="20"></p>
<p>计数器初始值<input type="text" name="curvalue" size="20"></p>
<p>主页地址<input type="text" name="pageurl" size="20"></p>
<p><input type="submit" value="提交" name="B1"><input type="reset" value="重写" name="B2"></p>
</form>
getcl.asp
' 处理用户的输入的表单,并加入数据库.
<%
Set conn = Server.CreateObject("ADODB.Connection")
' 建立与数据库的连接.
dbpath=server.MapPath("count.mdb")
' 取得数据库的实际路径.
conn.open "driver={Microsoft Access Driver (*.mdb)};dbq="&DbPath
set rs=server.CreateObject("adodb.recordset")
user=Request.Form("user")
pageurl=Request.Form("pageurl")
curvalue=Request.Form("curvalue")
' 取得用户信息.
sql="select * from counttable where user='"&user&"'"
' 检查用户名是否存在.
rs.Open sql,conn,1,3
if not rs.EOF then
Response.Write"<title>申请出错</title>"
Response.Write"噢,用户名已经存在!请重新选择...</title>"
Response.End
' 停止向下处理,要求用户重填.
end if
rs.AddNew
rs("user")=user
rs("pageurl")=pageurl
rs("curvalue")=curvalue
rs.Update
rs.Close
set rs=nothing
conn.Close
set conn=nothing
%>
[1]