asp用戶注冊(cè)示例代碼

字號(hào):


    asp用戶注冊(cè)示例代碼:
    數(shù)據(jù)庫設(shè)計(jì):
    表名:userinfo
    字段名 類型/長(zhǎng)度 說明
    id 自動(dòng)編號(hào) 用戶ID
    username text/16 用戶名
    password text/32 MD5 32位加密
    addtime 時(shí)間日期 注冊(cè)時(shí)間
    代碼如下:
    <%
    'asp教程用戶注冊(cè)示例
    'http://www.asp.org.cn
    dim db,conn,myconn
    db="asporgcn.mdb" '數(shù)據(jù)庫文件相對(duì)路徑
    Set Conn = Server.CreateObject("ADODB.Connection") '創(chuàng)建對(duì)象實(shí)例
    myconn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db&"")
    Conn.Open MyConn
    if request("submit")<>"" then '用戶點(diǎn)擊提交按鈕
    username=request("username")
    password=request("password")
    password2=request("password2")
    if password<>password2 then
    response.write("<script>alert('兩次輸入的密碼不對(duì)');window.history.back();</script>")
    response.end() '結(jié)束運(yùn)行
    end if
    set rs=server.CreateObject("adodb.recordset")
    sql="select count(0) from userinfo where username='"&username&"'"
    rs.open sql,conn,1,1
    if rs(0)>0 then '判斷用戶名是否已經(jīng)注冊(cè)
    response.write("<script>alert('用戶名已經(jīng)存在');window.history.back();</script>")
    response.end() '結(jié)束運(yùn)行
    else
    'response.write "insert into userinfo(username,password) values('"&username&"','"&password&"')"
    conn.execute("insert into userinfo([username],[password]) values('"&username&"','"&password&"')") '添加到數(shù)據(jù)庫注冊(cè)完成,password是ACCESS中的保留關(guān)鍵字。保留關(guān)鍵字用[]括起來就不會(huì)出錯(cuò)。
    response.write("<script>alert('注冊(cè)成功!');window.history.back();</script>")
    end if
    rs.close
    set rs=nothing '使用完RS后一定要記得關(guān)閉與釋放,否則占用服務(wù)器資源,在ASP程序面試時(shí),這一點(diǎn)一定要記住
    end if
    conn.close '關(guān)閉連接,
    set conn=nothing '釋放內(nèi)存 這兩句很重要,不然會(huì)占用大量服務(wù)器資源。
    %>
    <html>
    <head>
    <title>用戶注冊(cè)案例</title>
    <META content="中國(guó)ASP網(wǎng)編寫的用戶注冊(cè)案例教程。http://www.asp.org.cn" name=description>
    </head>
    <body>
    <form id="form1" name="form1" method="post" action="index.asp">
    <table width="400">
    <tr>
    <td>用戶名:</td>
    <td><label>
    <input name="username" type="text" id="username" size="16" maxlength="16" />
    </label></td>
    </tr>
    <tr>
    <td>密碼:</td>
    <td><input name="password" type="password" id="password" size="16" maxlength="16" /></td>
    </tr>
    <tr>
    <td>確認(rèn)密碼:</td>
    <td><input name="password2" type="password" id="password2" size="16" maxlength="16" /></td>
    </tr>
    <tr>
    <td colspan="2"><label>
    <input type="submit" name="Submit" value="提交" />
    </label></td>
    </tr>
    </table>
    </form>
    </body>
    </html>