I. ' Establishment of REGISTER.ASP
Copy Code code as follows:
<%@ Language=vbscript%>
<title> Registration Page </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<style type= "Text/css" >
TD img {Display:block}. STYLE2 {font-size:12px}
. STYLE3 {
Color: #FF0000;
Font-weight:bold;
font-size:16px;
}
</style>
<body bgcolor= "#ffffff" >
<table width= "531" border= "0" align= "center" cellpadding= "0" cellspacing= "0" >
<!--dwlayouttable-->
<!--fwtable fwsrc= "unnamed" fwbase= "Register.jpg" fwstyle= "Dreamweaver" fwdocid = "1502317357" fwnested= "0"-->
<tr>
<TD width= "rowspan=" "5" valign= "Top" bgcolor= "#D8FBB5" ></td>
<TD width= "209" height= "a" valign= "top" ></td>
<TD width= "204" valign= "top" ></td>
<TD width= "rowspan=" "5" valign= "Top" bgcolor= "#D8FBB5" ></td>
</tr>
<tr>
<TD height= colspan= "2" valign= "Top" ></td>
</tr>
<tr>
<TD height= "></td>"
<td></td>
</tr>
<tr>
<TD height= "colspan=" "2" valign= "Top" ><form id= "Form1" Name= "Form1" method= "Post" action= "result2.asp" >
<table width= "100%" border= "1" >
<tr>
<TD colspan= "3" ><span class= "STYLE2" > Please fill in your registration information below, red <span class= "STYLE3" >*</span> The options indicated are required </span></td>
</tr>
<tr>
<TD align= "center" valign= "Middle" > Username:</td>
<td><label>
<input type= "text" name= "U_user" id= "U_user"/>
</label></td>
<td><span class= "STYLE2" ><span class= "STYLE3" >*</span></span></td>
</tr>
<tr>
<TD align= "center" valign= "Middle" > Password:</td>
<td><label>
<input type= "text" name= "U_pass" id= "U_pass"/>
</label></td>
<td><span class= "STYLE2" ><span class= "STYLE3" >*</span></span></td>
</tr>
<tr>
<TD align= "center" valign= "Middle" > Name:</td>
<td><label>
<input type= "text" name= "I_name" id= "I_name"/>
</label></td>
<td><span class= "STYLE2" ><span class= "STYLE3" >*</span></span></td>
</tr>
<tr>
<TD align= "center" valign= "Middle" > Gender:</td>
<td><label>
<select name= "I_sex" size= "1" id= "I_sex" >
<option value= "1" > Male </option>
<option value= "2" > Women </option>
</select>
</label></td>
<td><span class= "STYLE2" ><span class= "STYLE3" >*</span></span></td>
</tr>
<tr>
<TD align= "center" valign= "Middle" > Age:</td>
<td><label>
<input type= "text" name= "I_age" id= "I_age"/>
</label></td>
<td><span class= "STYLE2" ><span class= "STYLE3" >*</span></span></td>
</tr>
<tr>
<TD colspan= "3" align= "center" valign= "Middle" ><label>
<input type= "Submit" name= "button" id= "button" value= "Submission of registration information"/>
<input type= "reset" name= "Button2" id= "Button2" value= "Reset form"/>
</label></td>
</tr>
</table>
</form></td>
</tr>
<tr>
<TD colspan= "2" valign= "Bottom" bgcolor= "#D8FBB5" ><!--dwlayoutemptycell--> </td>
</tr>
</table>
</body>
Second, establish a connection and open the database subroutine con1.asp
Copy Code code as follows:
<%
' Method of string connection to database
Set Conn=server.createobject ("Adodb.connection")
Conn. Open driver=driver do Microsoft Access (*.mdb); uid=admin;pwd=;D bq= "&server. MapPath ("Regdb1.mdb")
%>
Third, the establishment of Access database Db1.mdb, in which the data table user, the fields are: U_uid (Automatic), U_user (user name: Text type), U_pass (password: text type)
Set up the form data sent from the receiving register.asp and insert it into the data table user to register the successful display page: The result2.asp code is as follows:
Copy Code code as follows:
<%@ Language=vbscript%>
<!--#include file= "con1.asp"-->
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Registration Success </title><br>
<body>
<%
' Create a Recordset object method
Set Rst=server.createobject ("Adodb.recordset")
Set Rst1=conn.execute ("INSERT into User (U_user,u_pass) VALUES ('" &request.form ("U_user") & "', '" & Request.Form ("U_pass") & "')"
%>
<table width= border= "0" align= "center" >
<tr>
<TD align= "center" ></td>
</tr>
</table>
</body>
Five, press F12 preview register.asp and enter data, click submit button
When you open the datasheet, user will see:
Description The operation was successful because it has been submitted two times, so we see two new records inserted in the table, but there are duplicate records in the table, the following is added to the code in result2.asp to resolve:
Copy Code code as follows:
<%@ Language=vbscript%>
<!--#include file= "con1.asp"-->
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Registration Success </title>
<style type= "Text/css" >
<!--
. STYLE1 {font-size:24px}
-->
</style>
<br><%
' Create a Recordset object method
Set Rst=server.createobject ("Adodb.recordset")
Rst.open "SELECT * from user where u_user= '" &request.form ("U_user") & "", conn,1,1
If Rst.recordcount>0 Then
Response.Write "User name:" &request.form ("U_user") & "has been occupied, please click Back to register Again"
%>
<a href= "Register.asp" class= "STYLE1" > Return to Re-register </a>
<%
Response. End
Else
Set Rst1=conn.execute ("INSERT into User (U_user,u_pass) VALUES ('" &request.form ("U_user") & "', '" & Request.Form ("U_pass") & "')"
End If
%>
<table width= border= "0" align= "center" >
<tr>
<TD align= "center" ></td>
</tr>
<tr>
<TD align= "center" ><a href= "Register.asp" class= "STYLE1" > Return </a></td>
</tr>
</table>
</body>