The data code program accepts data submitted by users and then saves it to the database tutorial. It is very convenient to wait. Let’s take a look at a detailed explanation example. Example:
For example: enter: username, password, email, phone in the field name
Note: Different field names are separated by English commas, and asterisks are not supported.
Enter the name of the table to be queried in the table name field: for example: table1
Front form page:
Mainly pay attention to the name attribute of the input field.
The commonly used codes for adding data under asp are:
via adodb.recordset
The advantage is: database entry is relatively simple, and there is no need to consider single quotation marks. Less prone to errors.
Copy the code code as follows:
username = request(username)
password = request(password)
email = request(email)
telphone = request(telphone)
sql=select * from table1
rs.open sql,conn,1,3
rs.addnew
rs(username)=username
rs(password)=password
rs(email)=email
rs(telphone)=telphone
rs.update
rs.close
The second method is to use SQL data to achieve high warehousing efficiency, but it is prone to problems and needs to consider single quotation marks and other issues.
The above code is actually an encapsulation of the sql insert statement.
Copy the code code as follows:
set conn=server.createobject(adodb.connection)
'Create 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)&'))
Friendly reminder from Script House: For security reasons, in many cases it is necessary to perform inverse conversion on the content input by the user. For example using
username=server.htmlencode(request(username))
This will prevent some scripts from running, such as <script> will become <script>