[Switch] php Elementary tutorial (5) php form processing now introduces php form processing. here I will introduce two http message sending methods, get and post. For example, http: // host/1.php? Id = 6 & name = cosbeta then the 6 is sent to the server through get. the php script of the server will put this variable in the $ _ GET array. So now we can retrieve the value $ id = $ _ GET ['id']; // id = 6 $ name = $ _ GET ['name']; // cosbeta
Then we can see how users can transmit data to the server. For example, it is too tired to switch over ). First of all, there is such a form on the client. Note that if you want to post data, except ajax post (I will briefly introduce how to write ajax programs in the later advanced tutorial. if you want to learn, hurry up and get familiar with javascript.) in html, the input boxes must be separated and cannot be missed. if you accidentally miss one, you may have checked for a long time to see if the problem persists, because php is always unable to retrieve the post value, I have missed it. The following is an example.
Code login.html:
If you want to upload files in the form, enctype = "multipart/form-data" cannot be absent; otherwise, the upload will fail; method = post indicates that the form is submitted through post, so that the address bar of your browser will not show an address similar to id = xxx & name = xxx, you can change post to get on your own. For how to create the required form, you can first create the form you need with dreamweaver, and then view the html code, slowly, you will be familiar with the action, indicating that the script will be submitted to process the form.
The following is the login. php code.
$ Name = $ _ POST ['id']; // if it is submitted in get mode, use $ _ GET ['id'],
// If you cannot determine whether to submit the get or post REQUEST, use $ name = $ _ REQUEST ['id'].
$ Pass = $ _ POST ['pass'];
Echo "username:". $ name. "password:". $ pass;
// As I forgot to mention earlier, the connection string in php is completed with an English period,
// Example of this line
For the above example, the related descriptions are already in the annotations.
Now, put the two files in the root directory of your computer server, run http: // localhost/login.html, enter the user name and password, and click "GO" to test the file.
Let's take a look at the submission and data processing of forms. if you want to be more familiar with this, take the php manual I introduced in chapter 1 and check it out.
The next chapter will continue to explain the post-related file processing ......
Reference address: http://www.storyday.com/html/y2007/431_php-course-5.html