[此贴子已经被作者于2004-07-15 19:15:24编辑过]
数据插入页面:register.asp
<%@ language=vbscript %> <% response.buffer=true %> <html> <body> <% dim username dim email dim userpw dim address dim truename dim sex function sqlstr(data) sqlstr="'" & replace(data,"'","''") & "'" end function application.lock '接受数据 name=trim(request.form("username")) userpw=trim(request.form("userpw")) email=trim(request.form("email")) sex=request.form("sex") truename=trim(request.form("truename")) address=trim(request.form("address")) connstr="dbq="+server.mappath("register.mdb")+";defaultdir=; driver={microsoft access driver (*.mdb)};" set conn=server.createobject("adodb.connection") conn.open connstr '判断此用户是否已经存在 set rst=server.createobject("adodb.recordset") rst.activeconnection=conn sql="select *from register where username=" sql=sql & sqlstr(username) rst.source=sql rst.open if not rst.eof then response.write "此用户名已经存在,请选择其它的用户名重新注册!" rst.close response.end else sql="insert into register(username,userpw,email,truename,address,sex) values(' " sql=sql & sqlstr(username) & " ', ' " sql=sql & sqlstr(userpw) & " ',' " sql=sql & sqlstr(email) & " ',' " sql=sql & sqlstr(sex) & " ',' " sql=sql & sqlstr(truename) & " ',' " sql=sql & sqlstr(address) & " ')" conn.execute sql '插入数据库 application.unlock '完成数据库操作,可以释放锁定的数据库操作权限 response.write "<h2 align=center>注 册 成 功 , 请 <a href=""register.html"">登 陆</a>本 社 区 。</h2>" end if %> </body></html>
注册页面:register.html
<html> <head> <title>注册迷你sky虚拟社区</title> <script language=vbscript> <!-- sub tijiao_onclick() if len(register.username.value)<3 then msgbox "用户名太短,请输入一个长度大于3的名字!" register.username.select exit sub end if if instr(trim(register.username.value)," ")>1 then msgbox "用户名中请不要加入空格!" register.username.select exit sub end if if len(register.userpw.value)<4 then msgbox "密码太短,请选择一个长度大于4的密码!" register.userpw.select exit sub end if if register.userpw.value<>register.verifypw.value then msgbox "确认密码和密码不同,请确认您的密码!" register.userpw.value="" register.verifypw.value="" register.userpw.select exit sub end if if register.truename.value="" then msgbox "为了为您更好的服务,请输入您的真实姓名!" register.truename.select exit sub end if if register.email.value="" then msgbox "为了能为您更好的服务,请输入您的电子邮箱地址!" register.email.select exit sub else if not right(register.email.value,4)=".com" and not right(register.email.value,4)=".net" and not right(register.email.value,3)=".cn" or instr(register.email.value,"@")<=1 or instr(register.email.value,"@.") then msgbox "请正确输入您的电子邮箱地址!" register.email.select exit sub end if end if if register.address.value="" then msgbox "请输入您的详细地址!" register.address.select exit sub end if register.submit end sub --> </script> <style type="text/css"> <!-- .class1{border-style:solid;border-color:#666666;border-width:1;border-top:0px;border-right:0px;border-left:0px;} .class2{font:10pt;} .class3{font:12pt;} .class4{color:#ff00ff;} --> </style> </head> <body class=claass2 leftmargin=0 topmargin=30> <h2 align=center ><font size=6 face="华文楷体" color=#000000>欢迎成为迷你Sky虚拟社区的注册用户</font></h2> <hr size=1 color==#999933 width=800 align=center></hr><br> <font color=#ff0000 class=class2> 您的位置:注册页面 注意:带*号的项目为必填项目!</font><br><br> <form memthod="post" action="register.asp" name="register"> <table width="600" height="307" border="0" align="center" cellpadding="0" cellspacing="0" class=class3> <tr> <td width="227" align=center> 用户名:</td> <td width="373"><input type="text" name="username" size=30 maxlength=16 class=class1> <font class=class4>*</font></td></tr> <tr> <td align=center>选择密码:</td> <td><input type="password" name="userpw" size=30 maxlength=16 class=class1> <font class=class4>*</font></td></tr> <tr> <td align=center>确认密码:</td> <td><input type="password" name="verifypw" size=30 maxlength=16 class=class1> <font class=class4>*</font></td></tr> <tr> <td align=center>真实姓名:</td> <td><input type="text" name="truename" size=30 maxlength=16 class=class1> <font class=class4>*</font> </td></tr> <tr> <td align=center>选择性别:</td> <td ><input type="radio" checked name="sex" value="男">男 <input type="radio" name="sex" value="女">女 <font class=class4>*</font></td></tr> <tr> <td align=center>Email地址:</td> <td><input type="text" name="email" size=30 maxlength=50 class=class1> <font class=class4>*</font></td></tr> <tr> <td align=center>联系地址:</td> <td><input type="text" name="address" size=30 maxlength=255 class=class1> <font class=class4>*</font></td></tr> <tr> <td align=center><input type="button" name="tijiao" value="提 交"></td> <td><input type="reset" value="重 填" name="chongtian"></td> </tr> </table>
</form> </body></html>
[此贴子已经被作者于2004-07-17 19:45:48编辑过]