筆記 用application和session做的簡單計數器
<%
if isempty(session("conn")) then
application.lock
set counterfile=server.createobject("scripting.filesystemobject")
set temp=counterfile.opentextfile(server.mappath("count.txt"),1,true,false)
num=temp.readline
if num=empty then num=1
application("count")=num
application("count")=application("count")+1
temp.close
end if
%>
<center><h1>訪客人數:<font color=red><%=application("count")%></font></h1>
<%
set counterfile=server.createobject("scripting.filesystemobject")
set temp=counterfile.createtextfile(server.mappath("count.txt"),true,false)
temp.writeline(application("count"))
temp.close
application.unlock
%>
If Then 程式語句 End if 如
<%
score=request("score")
if not isnumeric(score) then
m="請輸入數字"
elseif score="" then
m="請輸入資料"
elseif score>=60 and score<=100 then
m="及格"
elseif score>100 or score<0 then
m="請輸入0---100之間的數"
else
m="不及格"
end if
%>
cookies:
<%
response.buffer=true ' 因是沒有在伺服器下載資料前就進行了交換,所以用緩衝區來裝下載的資料
var=request.cookies("var")
if var="" then var=empty '因為""不可與數值運算
response.write"開始var="&var&"<br>"
var=var+10
response.write"結束var="&var&"<br>"
response.cookies("var")=var
response.cookies("va").expires="2004/3/31/" '設定有效期間
%>
<%
set fs=server.createobject("scripting.filesystemobject")
source=server.mappath("1/1.txt")
target=server.mappath("1.txt")
on error resume next
fs.movefile source,target 'movefile換在deletefile\copyfile
if err.number=53 then
response.write source&"檔案不存在"
response.end
elseif err.number=70 then
response.write target&"檔案為唯讀或鎖"
response.end
elseif err.nuber<>0 then
response.write"other="&err.number
response.end
end if
%>
讀取常值內容
<%
set fs=server.createobject("scripting.filesystemobject")
file=server.mappath("1/1.txt")
set txt=fs.opentextfile(file,1,true)
if not txt.atendofstream then
line=txt.readline'可換成readall
response.write line&"<br>"
end if
%>
############################################
SERVER & Request]
<%=server.htmlencode("<i>原碼輸出</i>")%>
<%=request.servervariables("local_addr")%>'本地IP
<%=request.servervariables("remote_addr")%>'Client 端IP
串連access資料庫的兩種方法:
1、<% Set CN = Server.CreateObject("ADODB.Connection"
CN.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ="&Server.MapPath("message.mdb")
Set rs=Server.CreateObject("ADODB.Recordset")
%>
2、<% Set con = Server.CreateObject("ADODB.Connection")
DBPath = Server.MapPath("bbs.mdb")
con.Open "provider=microsoft.jet.oledb.4.0;data source="&DBPath
Set rs=Server.CreateObject("ADODB.Recordset")
%>
###########################################################################
如讀取表中的資料:
<%
Num=0
For Itemline=0 To Rs.recordcount-1 'recordcount-1 不會移出最後一筆記錄
Response.Write "<TR>"
For I=0 To Rs.fields.Count-1
Response.Write "<TD><input type=text name=" & Num & _
" value=" & Rs(I).Value & "></TR>"
Response.Write chr(10) '輸出分行符號
Num=Num+1
Next
Response.Write "</TR>"
Rs.MoveNext
If Rs.Eof Then Exit For '可省略
Next
%>
儲存資料檔案
###########################################################################
<%
Dim Item(100) '數組的多少很重要
For I=0 To 100
Item(I)=Request(I)
Next
Set conobject = Server.CreateObject("ADODB.Connection")
DBPath = Server.MapPath("exam.mdb")
conobject.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ="&DBPath
Set RS=Server.CreateObject("ADODB.Recordset")
RS.Open "Select * from first",conobject,1,3
Num=0
For Itemline=0 To Rs.recordcount-1
For Itemnum=1 To Rs.Fields.Count-1
Rs.Fields(Itemnum).Value=Item(Num)
Num=Num+1
rs.update
Next
Rs.MoveNext
If Rs.Eof Then Exit For
Next
Response.Redirect "editexam.asp"
%>
###########################################################################
判斷表單是否填寫完整
1、If name = "" Or email = "" Or subject = "" Or _
textmemo = "" Then
Response.Write "<script>alert('松子說了,不填完就別想留言!');history.go(-1);</script>"
Response.End
End If
從表中刪除一條記錄:
1、<a href=del.asp?ID=<%=RS("id")%> >刪除</a>
2、<%
id=request("id")
Set CN = Server.CreateObject("ADODB.Connection")
CN.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ="&Server.MapPath("new.mdb")
Set RS=Server.CreateObject("ADODB.Recordset")
RS.Open "new",CN,1,3
SQL="delete * From new where id="&id
cn.execute sql
response.redirect("index.asp")
%>
###########################################################################
保持文字框格式一致的問題:
<%
function th(str)
str=replace(str,"媽的","MD")
str=replace(str,"靠","KAO")
th=str
end function