Build a database-driven website using PHP and MySQL (5)
Source: Internet
Author: User
Although everything looks good, we still haven't achieved our goal of truly interacting with users. Our users should be able to enter arbitrary information and hand it over to PHP for processing. Next, let's take the example on the personalized welcome page. We want our users to enter their (or her) names and display them in the information at will. We want users to input data, we need to use HTML forms.
Here is the form code:
<Form action = "welcome. php" METHOD = GET>
First Name: <input type = text name = "firstname"> <BR>
Last Name: <input type = text name = "lastname">
<Input type = submit value = "GO">
</FORM>
Except that you can enter your name here, the effect of this form is connected to the second one above (use firstname = Kevin & lastname = Yank in the query string) exactly the same. When you press the submit button (marked as "GO"), the browser loads welcome. php and automatically adds variables and their values to the query string. The variable NAME is the NAME attribute in the input type = TEXT mark, and the variable value is the corresponding content entered by the user.
The METHOD attribute in the input type = TEXT mark is used to tell the browser how to send the variable name and variable value in the request. GET (the one we used above) means to pass variables in the query string, but there is another option. Displaying variables in query strings is not always satisfactory-it is sometimes technically unavailable. If your form contains a TEXTAREA identifier that allows users to input a large amount of text, the text is displayed too long in the query string, the maximum length of the URL supported by the browser is exceeded. Another method is to allow the browser to transmit information in a hidden manner. The code for this method is almost the same as the code for the form we saw above, but we changed the form method from GET to POST:
<Form action = "welcome. php" METHOD = POST>
First Name: <input type = text name = "firstname"> <BR>
Last Name: <input type = text name = "lastname">
<Input type = submit value = "GO">
</FORM>
This form is exactly the same as our previous one in terms of functionality. The only difference is that when you press the "GO" button, the URL of the page to be loaded does not have a query string. On the one hand, this allows you to submit a large amount of data or sensitive data (such as passwords) through a form, rather than displaying it in a query string. On the other hand, if a user adds the result page generated by the submission form to the Favorites folder, it is useless because it does not contain the submitted data. In addition, search engines such as AltaVista always use query strings to Submit Query conditions. The main reason is that you can easily add the query results page to favorites, in order to perform the same search in the future, because the search conditions are included in the URL.
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.