asp用戶注冊示例代碼

字號(hào):


    asp用戶注冊示例代碼:
    數(shù)據(jù)庫設(shè)計(jì):
    表名:userinfo
    字段名 類型/長度 說明
    id 自動(dòng)編號(hào) 用戶id
    username text/16 用戶名
    password text/32 md5 32位加密
    addtime 時(shí)間日期 注冊時(shí)間
    代碼如下:
    <%
    'asp教程用戶注冊示例
    '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)注冊
    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ù)庫注冊完成,password是access中的保留關(guān)鍵字。保留關(guān)鍵字用[]括起來就不會(huì)出錯(cuò)。
    response.write(<script>alert('注冊成功!');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>用戶注冊案例</title>
    <meta content=中國asp網(wǎng)編寫的用戶注冊案例教程。 name=description>
    </head>
    <body>
    <form id=form1 name=form1 method=post action=index.asp>
    <table width=400 border=1>
    <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>