,經常寫些系統,那麼一般都是從登入程式開始,每接乙個系統就寫一次登入,好麻煩。
乾脆直接做個登入驗證函式吧,對我來說,大都情況可以勝任了:)
<%
function chk_regist(requestname,requestpwd,tablename,namefield,pwdfield,reurl)
dim **_name,**_pwd
**_name=trim(request.form(""&requestname&""))
**_pwd=trim(request.form(""&requestpwd&""))
if **_name="" or **_pwd="" then
response.write("")
end if
set rs = server.createobject ("adodb.recordset")
sql = "select * from "&tablename&" where "&namefield&"='"&**_name&"'"
rs.open sql,conn,1,1
if rs.eof then
response.write("")
else
if rs(""&pwdfield&"")=**_pwd then
session("**_name")=rs(""&namefield&"")
response.redirect(reurl)
else
response.write("")
end if
end if
rs.close
set rs = nothing
end function
%>
引數說明:
chk_regist(requestname,requestpwd,tablename,namefield,pwdfield,reurl)
requestname 為接受html頁中輸入名稱的input控制項名
requestpwd 為接受html頁中輸入密碼的input控制項名
tablename 為資料庫中儲存註冊資訊的表名
namefield 為該資訊表中存放使用者名稱的欄位名
pwdfield 為該資訊表中存放使用者密碼的欄位名
reurl 為登入正確後跳轉的頁
引用示例如下:
2,經常有可能對某個事物進行當前狀態的判斷,一般即做一欄位(數值型別,預設值為0)
通過對該字段值的修改達到狀態切換的效果。那麼,我又做了個函式,讓自己輕鬆輕鬆。
<%
function pvouch(tablename,fildname,autoidname,indexid)
dim fildvalue
set rs = server.createobject ("adodb.recordset")
sql = "select * from "&tablename&" where "&autoidname&"="&indexid
rs.open sql,conn,2,3
fildvalue=rs(""&fildname&"")
if fildvalue=0 then
fildvalue=1
else
fildvalue=0
end if
rs(""&fildname&"")=fildvalue
rs.update
rs.close
set rs = nothing
end function
%>
引數說明:
pvouch(tablename,fildname,autoidname,indexid)
tablename 該事物所在資料庫中的表名
fildname 該事物用以表明狀態的欄位名(字段型別是數值型)
autoidname 在該表中的自動編號名
indexid 用以修改狀態的對應自動編號的值
引用示例如下:
<%
dowhat=request.querystring("dowhat")
p_id=cint(request.querystring("p_id"))
if dowhat="tj" and p_id<>"" then
call pvouch("**_products","p_vouch","p_id",p_id)
end if
%>
<%if rs("p_vouch")=0 then%>
>推薦
<%else%>
>取消推薦
3,為很多中小企業寫站點,一般產品展示是個大專案,那麼做成的頁面也就不同。
要不就是橫排來幾個,要不就是豎排來幾個,甚至全站要翻來覆去的搞個好幾次,麻煩也很累。
索性寫個函式能緩解一下,於是就成了下面
<%
function showpros(tablename,topnum,fildname,loopnum,typenum)
set rs = server.createobject ("adodb.recordset")
sql = "select top "&topnum&" * from "&tablename
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.write("暫時無該記錄")
else
response.write("")
for i=1 to rs.recordcount
if (i mod loopnum=1) then
response.write""
end if
select case typenum
case "1"
response.write("")
response.write(rs(""&fildname&""))
response.write("
")response.write("方式1之"&i&"記錄")'此處的「方式1」可以替換顯示為其餘欄位的值
response.write("
")'如果字段比較多,繼續新增新個**行來顯示
response.write("
")case "2"
response.write("")
response.write(rs(""&fildname&""))
response.write("
")response.write("")
response.write("方式2之"&i&"記錄")
response.write("
")response.write("
")end select
if (i mod loopnum=0) then
response.write""
end if
rs.movenext
next
response.write("")
end if
rs.close
set rs = nothing
end function
%>
引數說明:showpros(tablename,topnum,fildname,loopnum,typenum)
whichpro為選擇何型別的產品種類
topnum表示提取多少條記錄
fildname表示除錯顯示的字段,具體應用的時候可以省去該引數,在函式內部直接使用
loopnum表示顯示的迴圈每行的記錄條數
typenum表示迴圈顯示的方法:目前分了兩類,橫向並列、縱向並列顯示同一資料記錄行的不同記錄
引用示例如下:
<%
if request.form("submit")<>"" then
topnum=request.form("topnum")
loopnum=request.form("loopnum")
typenum=request.form("typenum")
else
topnum=8
loopnum=2
typenum=1
end if
%>
<%call showpros("**_products",topnum,"p_name",loopnum,typenum)%>
ASP中字串函式的應用
asp中字串函式的應用 email liuyong8833 sohu.歡迎前來學習交流!1.字串函式 len str 取得字串的長度 instr str1,str2 從字串str1,尋找另乙個字串str2第乙個出現的位置 left str,n 從字串str左起取n個字元 right str,n 從字...
ASP中CACHE技術的應用
asp從發布至今已經7年了,使用asp技術已經相當成熟,自從 微軟推出了asp.net之後就逐漸停止了對asp版本的更新。但是由於有很多人仍然習慣使用asp來開發 所以,再次我將以乙個簡單的例子來說明在asp中如何使用cache。code asp default.asp language vbscr...
asp中快取cache技術的應用
asp從發布至今已經7年了,使用asp技術已經相當成熟,自從微軟推出了asp.net之後就逐漸停止了對asp版本的更新。但是由於有很多人仍然習慣使用asp來開發 所以,再次我將以乙個簡單的例子來說明在asp中如何使用cache。簡單的說使用cache基本原理是,把經常需要且獲得代價昂貴的資料在記憶體...