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
[1]