Application function in ASP application

Source: Internet
Author: User
Tags html page numeric sql trim
function | Function 1, often write some system, then generally start from the login program, every system to write a login, good trouble.

Simply do a login verification function, for me, most of the situation can be competent:



<%
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" "Please complete the account password, thank you for your cooperation." ""); 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" ("") does not have this member ID, please confirm that has not been applied. ""); 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" "Reminder that your account number and password are not consistent. Pay attention to numbers and capitalization. ""); History.go ( -1) </script> ")
End If
End If
Rs.close
Set rs = Nothing
End Function
%>




Parameter description:
Chk_regist (Requestname,requestpwd,tablename,namefield,pwdfield,reurl)

Requestname an input control name that accepts an input name in an HTML page
Requestpwd the name of an input control that accepts a password in an HTML page
TableName The name of the table that holds the registration information in the database
Namefield the name of the field that holds the username for the information table
Pwdfield the name of the field that holds the user's password in the information table
Reurl the page to which the login is correct

Examples of references are as follows:



<%
Call Chk_regist ("B_name", "B_pwd", "Cn_admin", "Cn_name", "Cn_pwd", "admin.asp")
%>



Debug Address: http://www.cnbruce.com/test/function/regist.asp


2, it is often possible to make a judgment of the current state of a thing, generally do a field (numeric type, default value is 0)
The effect of state switching is achieved by modifying the field value. So, I did a function to make myself relaxed.



<%
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
%>




Parameter description:
Pvouch (TABLENAME,FILDNAME,AUTOIDNAME,INDEXID)

TableName The name of the table in the database where the object resides
Fildname the name of the field to indicate the state (field type is a numeric type)
Autoidname name of the automatic number in the table
IndexID value of the corresponding AutoNumber used to modify the state

Examples of references are as follows:


<%
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")%>> recommendation </a>
<%else%>
<a href=showpro.asp?dowhat=tj&p_id=<%=rs ("p_id")%>> Cancel recommendation </a>
<%end if%>




Debug Address: http://www.cnbruce.com/test/function/showpro.asp

3, for many small and medium-sized enterprises to write sites, general product display is a big project, then made a page is also different.
or the horizontal to a few, or vertical row to several, or even the whole station to toss and turn a few times, trouble is very tired.
Simply write a function to alleviate, so it became the following



<%
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 ("not currently logged")
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 (Mode 1 &i& record) ' Here's Mode 1 to replace the value shown as the rest of the fields
Response. Write (&q



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.