When a beginner learns php, the test case is the message board. In the past, when the database was not connected, I directly wrote the message entered by the user into a txt file, and then read the display from the txt file (~.~ ). I recently learned some knowledge about accessing the MySQL database using php, and rewritten the message board. The function is relatively simple. 1. The first is the form for submitting the message gustmo
When a beginner learns php, the test case is the message board. In the past, when the database was not connected, I directly wrote the message entered by the user into a txt file, and then read the display from the txt file (~.~ ). I recently learned some knowledge about accessing the MySQL database using php, and rewritten the message board. The function is relatively simple. 1. The first is the form for submitting the message gustmo
When a beginner learns php, the test case is the message board. In the past, when the database was not connected, I directly wrote the message entered by the user into a txt file, and then read the display from the txt file (~.~ ).
I recently learned some knowledge about accessing the MySQL database using php, and rewritten the message board. The function is relatively simple.
1. First, submit the message form guessbook. php to post. php.
2. Database Connection config. php
3. Verify post. php
When we insert data into the database, data must be processed to keep the input data in the original format when it is displayed. For example, if you do not escape the code and directly display it, for example, JavaScript code will be directly run on your page.
Here we useHtmlspecialchars Function. However, htmlspecialchars does not escape the line break \ r \ n. That is to say, if the data you insert contains a line break, the function does not display a line break when you escape the line feed. Therefore, you must use this function when displaying data.Nl2brFunction.
", Htmlspecialchars ($ patch); // insert database statement $ SQL =" insert into content (name, email, content, time) values ('$ name ', '$ email', '$ content', now () "; mysql_query ($ SQL); // insert success, return information echo" script "alert (' submitted successfully! Back to view! '); Location. href ='./guessbook. php'; script ";}?>
4. display the user message list, which can be displayed in the guessbook. php message form.
Include ("config. php"); // connect to the database $ SQL = "select * from content"; // The database query statement. The content is the table that the user leaves a message. $ Result = mysql_query ($ SQL, $ con );
5. Basic results: the results after CSS modification are as follows:
Http://www.phptogether.com/archives/10907