611Currently online
92Today's Reading
40Share Today
Multilingual display

How to learn MySQL? : [2] Use mysql to implement login function

2018-04-17 01:37:00

In the first section, we explained how mysql creates a database, how to create a table, how to add, delete, change and check data. This section on the basis of the previous session, using mysql login function, the login function is just a simple process action, is to know how to use mysql, rather than to introduce a programming language. Let's go!!!


mysql installer, a programming language, at will, here just talk about how to achieve, rather than specific implementation.


It is the login function, then you first need a login user record table, that is, the user table, write the table structure here, in order to better demonstrate the effect. The table structure is shown in the figure, and it is important to note that primay key means that this is a primary key, that is, this field cannot be empty, and it cannot be repeated. The best way is to add an automatically growing column, or it can be its own value, and then add 1 to the maximum value, which will use the sql max function. Example: select max(userid) from users; This is the maximum value. No value is null by default, that is, empty. The meanings of the table are as follows: id, user login name, user password.


After the table structure has been, it is necessary to insert a piece of data for our use, here please see the posted picture, sq represents the meaning of :1. Fetch the maximum value, because there is no data in the beginning, so insert a data for NULL2. The account and password are both admin.3. 4. Query the maximum value again and find that the maximum value is 1.


Here's how to implement the login using the programming language. The first step: you have to have an interface for users to enter the account and password, whether you are a web page (b/s) or an application (c/s), it is the principle of this. The second step: when the user clicks to log in, you need to know the account and password, the judgment can not be empty, the third step: Compare the obtained data to the database to see if the user name and password are the same. The same indicates that the login is successful, not the same indicates that the login fails. Step 4: Return the result to the user.


Specific code implementation, here is just simulated code, create a java class. Then create two methods, one method to verify whether it is empty, one to verify the value in the database, and whether the input is the same, it should be noted here that I did not directly give the link mysql data, just simulate the implementation, as long as the link database code is changed to the database. Here is just an idea, if you can not solve this yourself, you can send me a reply message, anytime to give you the answer. You can change username and password in the main method. To verify the results of the execution of the program in different cases.


In fact, this login function is very simple, not involved in too many things, in fact, you think, want to continue to learn deep, you think about how to log in. Think about the login system of the bank, you will understand that the login is not as simple as I said, now start from the simple to do, slowly deepen their knowledge.

Matters needing attention

At first, there may not be a good idea to understand the idea of programming languages, only to say, practice more, write more, and one day, you will find that, oh oh, this is how it should be, then you are good at it.


No human affairs are all right, but I can say is: Good luck!!