I. the analysis before programming should be a message board, and we also decided to adopt the database method, so we should start from the following steps: 1. enter the location where the message is written? 2. after the message is sent to the text box
I. analysis before programming
To make a message board, we also decided to adopt the database method, so we should start from the following steps:
1. enter the message
Where can I leave a message?
2. send messages
After entering the data in the text box, determine the method to transfer the data to a file, and then the file receives the variable.
3. enter the database
The next file imports the received data into the database. Therefore, we need to write the data into the database.
4. View Results
After writing the message into the database, it is important to view it in the browser. Therefore, we need to know how to read data from the database.
Second, make a file (write.htm) for filling in the message)
III. PHP variable transfer
Friends who are familiar with ASP may know that after transferring variables from one file to another, the second file receives data in the request. PHP seems simpler, when a file transfers a variable to another file and generates a variable, I will distinguish ASP from PHP for example.
1. ASP:
Form.htm:
Asp_to.asp:
The nickname you entered is: <% response. write (request. form ('nickname') %>
Brief description: in the first file, there is a text box named nickname and a confirmation button. after entering the information in the text box, click "OK ", the browser will submit the file to asp_to.asp. the file will show your content in the text box, response. write is to display the output, while request is to receive the variable "nickname ".
2. PHP:
Form.htm:
This file is similar to the above, but changes asp_to.asp to php_to.php, that is, to submit the input variable to a php file named php_to.php.
Php_to.php:
The nickname you entered is:
In this case, echo is the display output, which is equivalent to response. write in ASP while $ represents the variable. PHP variables are represented by $.
4. PHP database control
In the previous section, I first created a MySQL database and a data table. Next, we will give a brief example of how to allow PHP to control the database. [Example 1]
$ Id = mysql_connect ('localhost', 'root', 'adminpassword ');
$ Db = mysql_select_db ('gsbook', $ id );
$ Result = mysql_query ('select * from gsbook ', $ db );