ASP應用中的應用函數

來源:互聯網
上載者:User
函數|函數 1,經常寫些系統,那麼一般都是從登入程式開始,每接一個系統就寫一次登入,好麻煩。

乾脆直接做個登入驗證函式吧,對我來說,大都情況可以勝任了:)



<%
Function chk_regist(requestname,requestpwd,tablename,namefield,pwdfield,reurl)
dim cn_name,cn_pwd
cn_name=trim(request.form(""&requestname&""))
cn_pwd=trim(request.form(""&requestpwd&""))
if cn_name="" or cn_pwd="" then
response.Write("<script language=javascript>alert(""請將帳號密碼填寫完整,謝謝合作。"");history.go(-1)</script>")
end if
Set rs = Server.CreateObject ("ADODB.Recordset")
sql = "Select * from "&tablename&" where "&namefield&"='"&cn_name&"'"
rs.open sql,conn,1,1
if rs.eof then
response.Write("<script language=javascript>alert(""沒有該會員ID,請確認有沒有被申請。"");history.go(-1)</script>")
else
if rs(""&pwdfield&"")=cn_pwd then
session("cn_name")=rs(""&namefield&"")
response.Redirect(reurl)
else
response.Write("<script language=javascript>alert(""提醒,您的帳號和密碼是不吻合。注意數字和大小寫。"");history.go(-1)</script>")
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 為登入正確後跳轉的頁

引用樣本如下:



<%
call chk_regist("b_name","b_pwd","cn_admin","cn_name","cn_pwd","admin.asp")
%>



調試地址:http://www.cnbruce.com/test/function/regist.asp


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("cn_products","p_vouch","p_id",p_id)
end if
%>

<%if rs("p_vouch")=0 then%>
<a href=showpro.asp?dowhat=tj&p_id=<%=rs("p_id")%>>推薦</a>
<%else%>
<a href=showpro.asp?dowhat=tj&p_id=<%=rs("p_id")%>>取消推薦</a>
<%end if%>




調試地址:http://www.cnbruce.com/test/function/showpro.asp

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("<table width='100%'>")
for i=1 to rs.recordcount
if (i mod loopnum=1) then
response.write"<tr>"
end if
select case typenum
case "1"
response.Write("<td><table width='100%'><tr><td bgcolor=red width='50%'>")
response.Write(rs(""&fildname&""))
response.Write("</td><td bgcolor=black>")
response.Write("方式1之"&i&"記錄")'此處的“方式1”可以替換顯示為其餘欄位的值
response.Write(&q



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.