Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deal with forms in PHP Development

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to process forms in PHP development. The quality of the article is high, so Xiaobian shares it with you as a reference. I hope you have a certain understanding of relevant knowledge after reading this article.

After all, I underestimated the lethality of the word "sister" to the program apes. Today, without a picture of a treasure, I can still reach four digits in less than a day without a photo explosion, and it has become the post with the most comments on the day! Although the comments were all crooked, the girl still said to me very kindly that the girl was very concerned about the content here. Seeing this sentence, I immediately felt a sense of knowing that I would give up my life as a monarch. I wonder if my sister would be willing to marry me?

So many people see this series, I should still uphold the purpose of technical blogs, try to focus on technology, and discuss PHP development knowledge with the majority of beginners. However, in order to take care of the majority of recent program apes because of the title click, I will add some descriptions of the girl's performance in the learning process to the blog, and teach everyone how to cultivate feelings with the girl, oh, no, academic exchanges.

Since you are teaching girls web development, especially in the case of almost zero foundation, you must start from very basic things and have enough patience. However, there must also be strict teaching ideas, not to say what you think, so that girls will not only feel annoyed, but also learning efficiency is not high. Think about it, the girl is tired, the momentum of learning does not go, what can you do later? You haven't had time to show your depth of knowledge and rich development experience, and the girl has already abandoned you on the computer, and then, what else can there be?! To sum up: no method, no idea, no patience, doomed to lonely life.

In the previous article, we have basically introduced some things, which can be summarized as follows: 1) php code should be identified with tags (2) how to use echo statements to output html code, and about escaping with\(escape character) for ""(double quotes). (3) How PHP code mixes with HTML code. Then, on this basis, the next step is how to submit the form and the processing of the submitted form.

Step 3: Submit the form

In html syntax, we will use tags to identify forms. In Baidu encyclopedia, we can know that--forms are mainly responsible for data collection functions in web pages. That is, forms provide the system with the ability to submit data. So let's revisit the lines of code we wrote earlier, focusing on the content of the form section.

User Name: Password:

Looking at the above lines of code and comments, some people may think: This is too simple. I said at the beginning that the key to teaching girls to learn skills is patience. If girls know everything, why do they need you? Here, the key to explain to the girl is action="Controller.php", which means that after clicking the submit button, the page will jump to the Controller.php file, in other words-sister, form submission, is to submit the data to Conroller.php, which will process the data. (This explanation may be biased, but in order to make the girl better understand, this is also an expedient, the effect is good yo)

Step 4: Obtain and process data from submitted forms

Now that the form has been submitted, the next step must be how to retrieve and process the data in the form. If you talk about POST requests and HTTP protocols to your sister at this time, the girl will not get any effect except to be confused and give you two white eyes. You may say, landlord, your teaching method is very unscientific and incomplete. I won't argue with you for the time being whether it is scientific or comprehensive. Sometimes, it doesn't mean that it is good for the learner to talk in detail. It is most important to be able to carry on the teaching process.

Cut the crap, let's look directly at the code of Controller.php, and explain to the girl in the comments how PHP gets HTML form data.

See the *** sentence at the beginning: session_start(); and the comments that follow, the girl will definitely ask--what is a session? Session, colloquially speaking, is the process from the user entering the website to closing the browser. Using session in PHP is by registering several session global variables and using them in different pages or php files. The girl definitely couldn't understand what session was all about at once. As long as she knew about it temporarily, she would gradually deepen her understanding of it in the future.

Moving on to the code, we'll see from step 3 that the way to submit the form is POST, so we use the $_POST variable to get the data from the form. The index in square brackets [''] is the name in the form, and the value in the array $_POST is obtained by the index. *** is displayed on the page.

Putting data on the page is certainly a way of "processing." However, since it was a login function, the user name and password entered must generally match the settings in the system. For example, there is only one user name in the system is admin, and the password is 123456, so the user name entered in addition to admin should be denied login, and the password should also correspond to admin, which must be 123456. The judgment code is as follows:

Sister is very hard, morning I asked her the basic operation of the database is not familiar with, at night I asked her what to do, she said: in the database. At this time, my heart do not know how much moved, originally on a day of class quite tired of fatigue suddenly disappear quickly sit down in front of the computer code.

Why would I want her to review the database? Because our system is unlikely to have only one account, it is impossible to write all the accounts and passwords into PHP files. What we need to do is store this information in a database and pull it out when we need it. When do I need it? Of course, when the login needs authentication, which is now.

Step 5: Connect to MySQL Database

PHP provides complete functions to manipulate MySQL databases, providing functionality for everything from connecting databases, executing SQL statements, processing data result sets, to shutting down databases. Girls can use these functions to make MySQL database based Web development efficient and simple.

So, let's start with the most basic connection database. Please see the code:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report