II. Construction
1. Build the main form
First, we need to provide a form that allows users to enter registration information. These are HTML content and put them aside. Let's take a closer look at the specific ASP script for registration.
(1) change the single quotation marks in the data to two single quotation marks, and add the single quotation marks before and after
Function SqlStr (data)
SqlStr = "'" & Replace (data ,"'","''")&"'"
End Function
Note: This is a custom function used to convert the single quotes (') in user input into two single quotes (''). In ASP, double quotation marks are used to enclose strings. Therefore, the above "'" indicates a string with only one single quotation mark. Replace a single quotes with two single quotes, because in SQL statements, single quotes are used to represent variables. To avoid confusion, we need to enclose the single quotes in the string in two single quotes. All user input must be embedded into SQL statements as variables, so this function is essential.
(2) storage preparation
Id = Request ("id ")
Password = Request ("password ")
Nickname = Request ("nickname ")
Email = Request ("email ")
Sex = request ("sex ")
Note: it is not necessary to save the content from the user input form in the variable, but it is easier to read and write.
If Request ("name") = "" then name = "" else name = request ("name ")
If Request ("phone") = "" then phone = "" else phone = request ("phone ")
This is because the content is not mandatory. To prevent the user from entering any content and cause database operation errors, it is necessary to replace the fields not filled with spaces.
(3) establish a connection
Set conn = Server. CreateObject ("ADODB. Connection ")
Conn. Open "driver = {Microsoft AccessDriver (*. mdb)}; dbq =" & Server. MapPath ("bbssystem. mdb ")
Note: This section establishes a database connection and the database name is bbssystem. mdb. The only thing to note in this section is the application of the Server. MapPath function. Generally, do not directly use the directory name where specific directories are involved, instead of the Server. MapPath function. Make good use of functions such as Server. MapPath and Request. ServerVariables () to make your WEB applications more portable.
Set cmd = Server. CreateObject ("ADODB. Command ")
(4) query whether the author already exists
Set cmd. ActiveConnection = conn
Cmd. CommandText = "query author"
ReDim param (0) 'declares an array of parameters
Param (0) = CStr (id) 'cint cannot be ignored
Set rs = cmd. Execute (, param)
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service