asp用户注册示例代码
asp用户注册示例代码
发布时间:2015-06-05 来源:查字典编辑
摘要:asp用户注册示例代码:数据库设计:表名:userinfo字段名类型/长度说明id自动编号用户IDusernametext/16用户名pas...

asp用户注册示例代码:

数据库设计:
表名:userinfo
字段名 类型/长度 说明
id 自动编号 用户ID
username text/16 用户名
password text/32 MD5 32位加密
addtime 时间日期 注册时间
代码如下:
<%
'asp教程用户注册示例
'
dim db,conn,myconn
db="asporgcn.mdb" '数据库文件相对路径
Set Conn = Server.CreateObject("ADODB.Connection") '创建对象实例
myconn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db&"")
Conn.Open MyConn
if request("submit")<>"" then '用户点击提交按钮
username=request("username")
password=request("password")
password2=request("password2")
if password<>password2 then
response.write("<script>alert('两次输入的密码不对');window.history.back();</script>")
response.end() '结束运行
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 '判断用户名是否已经注册
response.write("<script>alert('用户名已经存在');window.history.back();</script>")
response.end() '结束运行
else
'response.write "insert into userinfo(username,password) values('"&username&"','"&password&"')"
conn.execute("insert into userinfo([username],[password]) values('"&username&"','"&password&"')") '添加到数据库注册完成,password是ACCESS中的保留关键字。保留关键字用[]括起来就不会出错。
response.write("<script>alert('注册成功!');window.history.back();</script>")
end if
rs.close
set rs=nothing '使用完RS后一定要记得关闭与释放,否则占用服务器资源,在ASP程序面试时,这一点一定要记住
end if
conn.close '关闭连接,
set conn=nothing '释放内存 这两句很重要,不然会占用大量服务器资源。
%>
<html>
<head>
<title>用户注册案例</title>
<META content="中国ASP网编写的用户注册案例教程。" 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>确认密码:</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>

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新asp.net教程学习
热门asp.net教程学习
编程开发子分类