Step by step, we will teach you how to use PHP + MySql to build website No. 3 Management page, mysqlno. 3

Source: Internet
Author: User

Step by step, we will teach you how to use PHP + MySql to build website No. 3 Management page, mysqlno. 3

Let's take a look at what this blog will introduce.

Our home page has been set up, and most of the content in navigation on the Left can also be clicked, with only"SearchAndI'm a writer"Two links.

After this tutorial, we will be able to complete the following functions:

This is our main interface


Click "I'm a writer ":


Click any link:


Page after Writers Logon:



Now, let's take a step:

ClickI'm a writerThe following link is as follows:


"Admin/index. php"So we need to create a new folder on the host, name it admin, and edit index. php, which is the login page for the author today.

For ease of explanation, from now on, if no special instructions are added, all the files areAdminThe directory structure is as follows:


Next, let's start developing the author page!

Index. php


This page is very simple, as you can see from the picture at the beginning, that is, the content of the two rows of form. A link points to the content to be explained in this article.Writer. php, And the other link points to publish. php.

Next let's take a look

Writer. php



Let's go firstOverallLet's take a look at how writer. php completes what we want, and then we will explain in detail some of the functions that appear in it later.

4th rows

A new file is included.Include_fns.phpNote: This is also in the admin folder. Some functions will be used in writer. php, and these functions are included in this include_fns.php.

6th rows

It is determined that a user is logged on at the moment, and this function will include in the file referenced previously. If no user logs on, executeLogin_form ()Function to display the user login form. Otherwise, the article information of the current login user will be displayed.

13th rows

Get_writer_record FunctionThis line is used to return the user's related information. Then, in lines 15-19, this line is displayed based on the user's information:


Lines 21-23

This select statement should be simple, that is, to find all the articles published by the current user and sort them by creation time in reverse order.

25-28 rows

Based on the user's record, it is displayed that the user has a total of several articles, and a new page is attached to the add article.Story. phpIn the next blog


30-59 rows

The content here should not be hard to understand. Similar content was previously displayed to users based on the searched article information, and several links are provided for more operations:Edit (story. php), delete (delete_story.php) and keywords (keyword. php)And so on.

Well, the overall framework here is clear. Next let's look at several new functions separately.


Let's take a look.

Include_fns.php


Actually, it's very easy, right? Here we introduce two new PHP files, one isDb_fns.php under the upper-level directoryIn this article, we are already familiar with this. It is a function used for database links and operations. Note that the introduced format is:../Db_fns.php;

The other is our series of user functions.User_auth_fns.php.


Check_auth_user () function

This function appears inUser_auth_fns.phpFile:


It is very simple. I will not discuss it much.


Login_form () function

Still in the user_auth_fns.php file:


This function is still not difficult. It is also the content that has appeared before. It is the input of a form. After the login button is clicked, the request isLogin. phpPage. The sending method isPost.

The login. php page is still very simple. Let's look at it:

Login. php


There are two key points:

1Yes LoginFunction, which is still from the user_auth_fns.php file:


Based on the two input parametersUsername and password, Are all the content previously entered by the user, and then compare it with the writers table in the database. If it is found, it indicates that the user name and password entered by the user are valid, and 1 is returned; otherwise, 0 is returned.

2

Yes we seeHeader ('location: '. $ _ SERVER ['HTTP _ referer'])The function is used to return to the previous page and refresh the logon;

The previous page is writer. php, because the user has logged on, so in writer. when php's first if statement is made, it is concluded that there are already logged-on users, so it jumps to 11 lines to Display User articles.


Let's take a look:

Get_writer_record Function

Because it is a database-level operation, this function is stored inDb_fns.php.



This is basically the content. At this point, we have completed user login, post display, and other page operations, this section is a bit more content, please digest it. You can leave a message to discuss the differences.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.