Home > Backend Development > PHP Tutorial > Use PHP to create a news management system, use your brain to learn it! ! ! (Including front and back office)

Use PHP to create a news management system, use your brain to learn it! ! ! (Including front and back office)

慕斯
Release: 2023-04-10 07:12:02
forward
7721 people have browsed it

Do you know how to write a news release system based on PHP in code? Presumably many college students will ask you to use PHP to develop some systems in their final exams, so hurry up and learn it! ! !

Use PHP to create a news management system, use your brain to learn it! ! ! (Including front and back office)

##2.

Requirements analysis

1.

Software functions

News Release System (News Release System or Content Management System) is also called content management system CMS (Content Management System). is a network-based news release and The management management system is a system based on B/S mode. This system can complete almost all functions of news release. With the use of online news release systems, the Internet serves as a more important news media than television newspapers.

Our design of this system is the prerequisite for realizing the function of this system. The first is to provide a publishing function and news classification management. Secondly, realize user interaction, users can participate in comments on the news. Finally, comprehensive management of this news release must be achieved to facilitate the management of administrators.

To realize this huge function, we first divide user permissions. Different users have different permissions. Visitors (those who have not logged in) enter the main page of the news release system and can browse all related news and view other people's comments. But there are no special privileges. Registered viewers (users) not only have all the functions of guest viewers, but can also comment on a certain news. Finally, there is the administrator, who has the highest authority and can manage all news and news categories. New news categories can be added and modified, and new news content can also be added and modified.

2,

Software interface

According to the basic functions that the news release system should have and the user's requirements for the news release system, we will carry out the functional modules of this news release system division to facilitate the implementation of each function. At the same time, it is also very convenient and intuitive for users to use. Therefore, after our repeated analysis and design, we divided this news release system into 9 functional modules. The detailed function module names are as follows:

(1) News classification browsing module

(2) News retrieval module

(3) Module for posting news comments after user login

(4) Module for user login and registration

(5) Module for administrator background news release

(6) Administrator backend news management module

(7) Administrator backend news category addition module

(8) Administrator backend news category management module

(9) Administrator backend comment review module

3.

Software design

1.

Database design

Database design is the core of database design in CMS department. Database design directly determines the functional process of the CMS system and the efficiency of the operating system. Therefore, the design of the database requires careful consideration. Make sure to take into account all functions of the news release system.

The database is designed with the following data items:

(1

) News category: Category ID, category name.

(2) User information: UserID, username, login password.

(3) Administrator information:

AdministratorID, user name, login password, occupation. (Administrators can only be added by manipulating the database)

(4

) News release: News ID, published administratorID, category ID, title, imageURL, content, release time, number of clicks, attachmentURL.

(5) Comment information: commentID, userID, newsID, comment content, comment time, review status, publisher IP.

create database news;

use news;

create table category(

     category_id int auto_increment primary key,

     name char(20) not null

);

create table users(

     user_id int auto_increment primary key,

     name char(20) not null,

     password char(32)

);

create table admin(

     admin_id int auto_increment primary key,

     admin char(20) not null,

     apassword char(20),

     position char(20)

);

create table news(

     news_id int auto_increment primary key,

     admin_id int,

     category_id int,

     title char(100) not null,

     picture char(50),

     content text,

     publish_time char(30),

     clicked int,

     attachment char(100),

     constraint FK_news_admin foreign key (admin_id) references admin(admin_id),

     constraint FK_news_category foreign key (category_id) references category(category_id)

);

create table review(

     review_id int auto_increment primary key,

     user_id int,

     news_id int,

     content text,

     publish_time datetime,

     state char(10),

     ip char(15),

     constraint FK_review_users foreign key (user_id) references users(user_id),

     constraint FK_review_news foreign key (news_id) references news(news_id)

);
Copy after login

2. Software design

The news release system is divided into two parts: the front desk and the back desk. For front-end operators, The front-end page of the CMS system is the part they can see, so the front-end operation is required to be as intuitive and convenient as possible. Users can easily browse related news by opening the front page. They can directly query the news and directly browse the relevant news. At the same time, you can browse different types of news according to different categories of news. Registered users can log in through the login interface. After the user successfully logs in, he will have the right to comment. When the user needs to comment on the news after browsing some news, he only needs to enter the corresponding comment section of the news to add the content he wants to comment on, and he can successfully add it. At the same time, return to continue browsing other people's comments.

For backend management, the administrator not only has the authority to operate all functions of the frontend, but can also conduct comprehensive management of the website. Specifically, in news management, the administrator can set and add new news categories so that the news categories can be displayed on the front page. At the same time, the existing news categories can be modified. At the same time, the administrator can add and Delete news. Ensure the dynamics of the website. Secondly, the administrator is responsible for comprehensive management of news articles, such as review of comments, etc.

IV. Software implementation

(1)News classification browsing module

Browsing news is for all users With the most basic permissions, in order to facilitate users to browse news quickly, we have designed a classified browsing function for news. As long as the user enters the homepage of the news release system and wants to browse which type of news, he only needs to click on the name of the news category on the homepage to pop up all the news of the type of news he wants to browse. And arrange all news in the order of the time of news release. In the opened news list of this type of news, users only need to click on the corresponding news title to quickly browse the detailed content of this news. Including the title of the news, the detailed content of the news, the source of the news, the release time of the news and the number of clicks, etc. Therefore, it provides convenience for users who like to pay attention to which type of news. At the same time, this news release system also adds two news browsing modules. One is to list the most popular news for users based on the number of clicks on the news. That is, the news with the highest number of clicks. The other is to list the latest news for users based on the time when the administrator published the news.

Therefore, the different needs of different users can be met through this 3 block news browsing function module.

Use PHP to create a news management system, use your brain to learn it! ! ! (Including front and back office)Core code:

<section>

<p id="yule" class="heading">娱乐</p>

<p class="content">

<ul class="list">

<?php

$sql= "select * from news where category_id=1";

$newsRes = mysql_query($sql);

while($news = mysql_fetch_array($newsRes)){

echo"<li><a href=&#39;content.php?news_id=".$news[0]."&#39;>$news[3]</a></li>";

}

?>

</ul>

</p>

</section>
Copy after login

(2)News retrieval module

In order to facilitate users to browse quickly To browse news, we design a news retrieval function for this news release system. News retrieval means that the user only needs to find the news retrieval input box on the homepage of the news release system, then enter the keywords to query news in the query input box, and then submit it to the database. The database matches the data and then returns the news content the user wants to query. This retrieval method is more convenient. As long as the news contains the keywords entered by the user, the matching news will be displayed in a list. Therefore, users can intuitively browse the news they want to browse, saving users time and avoiding unnecessary browsing operations.

Use PHP to create a news management system, use your brain to learn it! ! ! (Including front and back office)Core code:

$sql="select * from news where title like &#39;%{$find}%&#39; order by news_id limit {$num} , $fnum";

//echo $sql;

$result=mysql_query($sql);

while($row=mysql_fetch_array($result)) {

$sqls="select name from category where category_id={$row[&#39;category_id&#39;]}";

$selected=mysql_query($sqls);

$a=mysql_result($selected,0);

$b=$row[&#39;news_id&#39;];

            echo "<tr>";

            echo "<td style=&#39;color:white;&#39;>{$a}</td>";

            echo "<td style=&#39;color:white;&#39;><a href=content.php?news_id=$b style=&#39;color:white;&#39;>{$row[&#39;title&#39;]}</td>";

            echo "</tr>";

        }
Copy after login

(3)Post news comment module after the user logs in

For users, you can Log in. After logging in, you can continue to browse the corresponding news. The difference is that logged in users have higher permissions than ordinary guest users. Login users can post their own news comments on the news while browsing the news content. Users can communicate with each other in the comment board. Form an interactive platform.

Use PHP to create a news management system, use your brain to learn it! ! ! (Including front and back office)Core code:

<?php header("Content-type:text/html;charset=utf-8");

    $server=@mysql_connect("localhost", "root", "")or die("数据库连接失败!");

    mysql_query("SET NAMES &#39;UTF8&#39;");

    $dblink=@mysql_select_db("news") or die("选择当前数据库失败!");

  $newsid=$_GET[&#39;news_id&#39;];

  //echo &#39;<script>alert(&#39;.$newsid.&#39;);</script>&#39;;

  $sql="select * from news where  news_id =".$newsid;

  $rs=mysql_query($sql);

  while($rows=mysql_fetch_array($rs)){

  $title = $rows[&#39;title&#39;];

  $content = $rows[&#39;content&#39;];

  $picture = $rows[&#39;picture&#39;];

  }

  $sql="select * from review where  state=&#39;已审核&#39; and news_id =".$newsid;

  $rs=mysql_query($sql);

  @$userid=$_SESSION[&#39;user_id&#39;];

?>
Copy after login

(4)User login and registration module

Restrict user permissions , the user login module is essential. You can log in normally if your account and password are correct. Ordinary users choose user login, while administrators choose administrator login. You can also register as a user.

Use PHP to create a news management system, use your brain to learn it! ! ! (Including front and back office)

Use PHP to create a news management system, use your brain to learn it! ! ! (Including front and back office)

核心代码:

<p class="box_lg">

<p class="box_tit">

<a href="" class="close">x</a>

<H3>登录账号</H3>

</p>

<p class="box_con">

<form action="login.php" method="post">

<p>

<select name="usertype">

<option value="普通用户">普通用户</option>

<option value="管理员">管理员</option>

</select>

</p>

<p>

用户名:<input type="text" name="name" size="11"/><br/>

</p>

<p>

密 码 :<input type="password" name="password" size="11"/><br/>

</p>

<p class="log">

<input type="submit" name="login" value="登录">

</p>

<span>

<a href="#" id="ljzc">立即注册</a>

</span>

</form>

</p>

</p>

<p class="box_zc">

<p class="box_tit">

<a href="" class="close">x</a>

<H3>注册账号</H3>

</p>

<p class="box_con">

<form action="adduser.php" method="post">

<p>

用户名:<input type="text" name="name" size="11"/><br/>

</p>

<p>

密 码 :<input type="password" name="password" size="11"/><br/>

</p>

<p>

确认密码:<input type="password" name="repassword" size="11"/><br/>

</p>

<p class="zc">

<input type="submit" name="zhuce" value="注册">

</p>

<span>

<a href="#" id="ljdl">立即登录</a>

</span>

</form>

</p>

</p>
Copy after login

(5)管理员后台新闻发布模块

新闻发布模块对于新闻发布系统来说是最主要的一个模块。本系统的新闻发布系统模块中发布的信息包括了新闻作者,新闻标题,新闻图片,新闻内容,新闻来源,新闻发布的时间以及用户点击次数等。管理员用户可以通过后台的新闻发布页面填写相关的内容,然后点击发布新闻,即可将自己的新闻发布出去。新闻发布的过程简单易行,新闻由管理员在后台直接发布,无需验证和批准直接可以在新闻发布系统的主页面上显示最新的新闻内容。

Use PHP to create a news management system, use your brain to learn it! ! ! (Including front and back office)核心代码:

<?php

include_once("functions/database.php");

get_connection();

$result_set = mysql_query("select * from category");

close_connection();

while($row = mysql_fetch_array($result_set)){

?>

     <option value="<?php echo $row[&#39;category_id&#39;];?>"><?php echo $row[&#39;name&#39;];?></option>

<?php

}

?>
Copy after login

(6)管理员后台新闻管理模块

管理员将新闻发布以后,难免有出错或者需要修改的时候。因此在设计后台的时候针对此需要,我们设计了管理员后台新闻管理模块。管理模块是对已经发布出去的新闻进行修改编辑或者删除。同时也是新闻发布系统管理新闻的最基本的功能。 此权限也只能是管理员才可以对此进行操作,对于游客身份的用户和已经登录的会员用户则均不可以对此进行操作。

Use PHP to create a news management system, use your brain to learn it! ! ! (Including front and back office)核心代码:

<?php

include_once("functions/database.php");

$news_id = $_GET["news_id"];

get_connection();

$result_news = mysql_query("select * from news where news_id=$news_id");

$result_category = mysql_query("select * from category");

close_connection();

$news = mysql_fetch_array($result_news);

?>
Copy after login

(7)管理员后台新闻类别添加模块

为了满足用户对新闻的分类浏览,我们设计了新闻的分类浏览功能。因此,在后台的管理中我们首先要建立管理员后台新闻类别添加的模块。管理员要发布的新闻是有一定的分类的。首先管理员要添加自己所要发布新闻的新闻分类,以便在以后发布新闻的时候可以根据已经添加的新闻分类,自然地将需要发布的新闻进行分类。同时网页中的新闻分类里也显示已发布的新闻。这样用户在针对哪一类的新闻进行浏览时,可以在第一时间看到最新的新闻。 如果网站需要宽展发布一些新类型的新闻,就可以动态的控制不同种类的新闻,可以做到新闻种类无限扩展。因此,此模块可以大大的增加动态网站的动态性,避免过的冗余操作。为管理员减少工作量,方便维护整个庞大的网站。

Use PHP to create a news management system, use your brain to learn it! ! ! (Including front and back office)

核心代码:

<?php

include_once("functions/database.php");

$category = $_POST["category"];

//$content = htmlspecialchars(addslashes($_POST["content"]));

 

$sql = "insert into category values(null,&#39;$category&#39;)";

get_connection();

mysql_query($sql);

close_connection();

echo  "该类别成功添加到数据库表中!";

?>
Copy after login

(8)管理员后台新闻类别管理模块

为了满足用户对新闻的分类浏览,我们设计了无限新闻类型添加的功能。与此同时,新闻的分类管理也是必不可少的一项模块。我们针对已经添加过的新闻进行修改或者直接删除,保证管理员可以对新闻分类进行任意操作。动态的控制整个新闻发布系统的新闻分类功能。同时也满足了不同用户对不同类型的新闻浏览的要求。使得这个新闻发布系统更有实用性,更人性化的管理。

Use PHP to create a news management system, use your brain to learn it! ! ! (Including front and back office)

核心代码:

<?php

include_once("functions/database.php");

 

$category_id = $_POST["category_id"];

$name = $_POST["category_name"];

 

$sql = "update category set name=&#39;$name&#39; where category_id=$category_id";

get_connection();

mysql_query($sql);

close_connection();

echo "新闻类别修改成功!";

?>
Copy after login

9)管理员后台评论审核模块

使管理员审核评论,防止存在非法或者违规的评论存在。

Use PHP to create a news management system, use your brain to learn it! ! ! (Including front and back office)

核心代码:

<?php

include_once("functions/database.php");

$review_id = $_GET["review_id"];

$sql = "update review set state=&#39;已审核&#39; where review_id=$review_id";

get_connection();

mysql_query($sql);

close_connection();

header("Location:review_list.php");

?>
Copy after login

  推荐学习:《PHP视频教程》           

The above is the detailed content of Use PHP to create a news management system, use your brain to learn it! ! ! (Including front and back office). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template