Course 4 of ASP literacy course-Data Acquisition

Source: Internet
Author: User
Article from http://www.7di.net
I thought for a long time and didn't come up with a good question. So I will use the four words of data for the moment as the question in this section!

As we mentioned in the previous lesson, <form method = post action = "Doing. asp "> </form> we can understand it as a box, and its professional name should be form, including various projects in form (for example: <input type = "text" name = "title"> here, you should note that <br> code is not a form, it is just used to modify the html common code of the page) we call it a form. We can see that if the user says "form", then you should know that the scope of the user is the various items included in the form and the form itself.

In this lesson, we will focus on how to accurately obtain the entered data after you click the "Submit" button if you have entered the title and content of the message.

See the following code:

The HTML code snippets attached to this Article are as follows:

<%
'Define variables
Dim Title, Message

 

'Get form data
Title = Request. Form ("Title ")
Message = Request. Form ("Message ")

 

'Display the obtained data
Response. Write ("Message Title:" & Title & "<br> ")
Response. Write ("Message content:" & Message)
%>

Now let's talk about the above Code.
'Define variables
This line of code is used for comments. Note: The Code after the comments will never be executed. The comments here are: defining variables.
Note advantages:
Watching properly will make your program better read, and commenting on the code will not reduce the program running speed
Annotation method:
'Is the only comment method in asp scripts.
Scope:
The comment only applies to the statements before single quotes and line breaks.

Dim Title, Message
This line is used to define variables. Here two variables are defined consecutively: title and message.
Note: 1. Asp is case-insensitive.
Note: 2. The variables in asp can be directly used without definition. Therefore, the Dim Title and Message line is deleted and the program will not go wrong.
Advantages of defining variables:
It can increase readability for your program, just as we pay more attention to the cause, process, and result when writing an article. Here, we can regard defining variables as the cause of things, if we do not define it, it is also legal, but it seems that there is no reason for the incident to go through and result directly. I personally think: learning program development is not about learning specific implementation methods, but about learning a way of thinking, that is, compiling ideas, and cultivating good programming habits, for the so-called good programming habits, just add comments and define variables in this lesson.
Rule for defining variables:
Variable naming must follow the standard naming rules of VBScript (asp is actually a subset of vb and its name is VBScript. Variable naming must follow:
The first character must be a letter. (The variable a1 is valid, but 1a is invalid)
Cannot contain embedded periods. (Similar to a: B is illegal)
It cannot exceed 255 characters. (There is a length limit. do not define it too long)
It must be unique within the declared scope. (Similar to Dim a, B, and a. Three variables are defined here, So errors will certainly occur because a is defined twice)
Variables cannot be reserved by the system. (Dim sub, function, if, dim, and so on are not allowed)
Summary:
1. The first character must be a letter.
2. Do not include punctuation marks
3. Do not include duplicate variables in the same program
4. Variable should be as complex as possible, but not lengthy
The following variables are valid.
A_ B, int_1
Variable definition method:
The most common method is to use the Dim statement. After Dim, you must leave a space and enter the variable name. Multiple Variable names are separated by commas, of course, there are other definition methods. We will not talk about them for the moment, but only about what we use.
Variable value:
What is pay? Let me give you an example and you will understand that I am not married yet. I named my future Beibei "Feng xiaojian ", we can understand this process as defining variables, but I don't have Beibei. Isn't it a void check? It doesn't matter. When I have a child in the future, then I asked him to give him the name. Okay, now it's a real name, and it's worth it.
A = B (let the value of variable a be equal to the value of variable B)
A = "B" (let the value of variable a be equal to character B)
A = 1 (let the value of variable a be equal to the number 1)
These are all pay values. When you pay the value, the value or variable on the right of the equal sign will be paid to the variable on the left of the equal sign.

Next let's take a look.
Title = Request. Form ("Title ")
This line is used to obtain the title of the message in the form. You will be asked here. How do I know that this line is the title, not the content, let's take a look at the Code <input type = "text" name = "title"> in the previous section, pay attention to this name, and then pay attention to the name of the message content, you will understand.
That is to say, in this sentence, the program will retrieve data from the project whose form project name is title from form.
Here we will talk about the Request. Its common understanding is to obtain
There are three most common methods to obtain data:
Request. Form (obtained from the Form)
Request. QueryString (obtained from the IE Address Bar)
Request (can be obtained from the form or IE Address Bar)
Here I want to emphasize that we try to use the first two methods to obtain them, and the third method is not used as much as possible. Because of its low efficiency, it will reduce your program running speed. It is not useless, it is used in a special situation.
Request. Form ("Title") is obtained from the form with name being title in Form. As for brackets and double quotation marks, these are fixed statements. You just need to memorize them.
Let's take a look at the Title =. We have already told you about the variable value payment just now, that is to say, to pay the variable title value, and the value of the title is that we use the request. obtained by form

Next, let's look at it.
Response. Write ("Message Title:" & Title & "<br> ")
This sentence is output
There are three common response types, so you must stick them back.
Response. write ("output content") (used to display the content, or print the content to your monitor)
Response. redirect ("Jump page address") (Program jump, for example, you write a line of response. redirect ("http://bbs.7di.net") then jump to the Forum)
Response. end () (the program is forcibly terminated, and the program will not be executed after termination)
Response. Write usage
When the string is displayed, the following two writing methods are valid:
Response. write ("string content ")
Response. write "string content"
When it displays variables, the following two writing methods are valid:
Response. write (variable name)
Response. write variable name
As you can see,When the program code is connected to the string, the string must have double quotation marks. This is not required when the program code is connected to variables and numbers, the "&" (read: ANDE) symbol is required when a string is connected to a variable or a variable is connected to a variable.
Let's analyze Response. Write ("Message Title:" & Title & "<br> ")
Response. write is used to display. () These two parentheses are his fixed mode. Double quotation marks are required for connecting programs and strings. Therefore, the comment title: Double quotation marks are placed at the front. Double quotation marks are required for connecting strings and programs, therefore, the Title of the message: there are double quotation marks behind it. When the string and the variable are connected, the "&" (read: amde) symbol is required. Therefore, the front side of the Title is "&". Similarly, it is easy to understand.

Last, let's talk about <% and %>. This is the identifier of asp. All asp code must be put in this range and be memorized.

Now that I have finished my presentation, I will immediately ask a question if I have any questions. In addition, I will debug it on my computer and reply the debugging results to me, so that I can get to know your progress in general.

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.