The actual PHP news management system uses the bootstrap framework.

Source: Internet
Author: User

The actual PHP news management system uses the bootstrap framework.

I just got started with PHP and wrote a news management system modeled on the video. The bootstrap framework is also used.

Write down your ideas.

This is a very simple system. The first is to create a database table.

Mysql> create database newsdb

Mysql> create table news (
-> Id int unsigned not null auto_increment primary key, // This is the news id
-> Title varchar (64) not null, // This is the title of the news.
-> Keywords varchar (64) not null, // This is the keyword of news.
-> Author varchar (16) not null, // This is the author of the news.
-> Addtime int unsigned not null, // This is the time when news was added.
-> Content text not null); // This is the news content.

In this way, the database table is built, and the page is written below.

First, write a database configuration file dbconfig. php:

Define (HOST, "localhost"); // HOST name

Define (USER, "root"); // USER Name

Define (PASS, ""); // Password

Define (DBNAME, "newsdb"); // Database Name

?>

Then there is a menu. php file






HTML5 & BootStrap













    News Management System
  • Browse news

  • Publish news









<Script type = "text/javascript" src = "bootstrap-3.2.0-dist/js/jquery-1.9.1.min.js"> </script>
<Script type = "text/javascript" src = "bootstrap-3.2.0-dist/js/bootstrap. js"> </script>
<Script type = "text/javascript" src = "pret0000-4-Mar-2013/pret0000. js"> </script>

After completing the preceding two steps, compile the homepage http://blog.csdn.net/q114942784/article/details/index.php:

First, import menu. php In the navigation bar.

Then add a title and a table.

Browse news







Require ("dbconfig. php ");

// 2. Link to mysql and select database

$ Link = @ mysql_connect (HOST, USER, PASS) or die ("An error occurred while connecting to the database! ");

Mysql_select_db (DBNAME, $ link );

// 3. Execute the query and return the result set

$ SQL = "select * from news order by addtime desc ";

$ Result = mysql_query ($ SQL, $ link );

// 4. parse the result set and traverse the output

While ($ row = mysql_fetch_assoc ($ result )){

Echo"

Echo"

Echo"


Echo"


Echo"


Echo"


Echo"


Echo"


Echo"

}

// 5. Release the result set

Mysql_free_result (& result );

Musql_close ($ link );

?>

// 1. Import the configuration file

"; "; "; "; "; "; "; "; "
News id Title Keywords Author Time Content Operation
{$ Row ['id']}{$ Row ['tilte ']}{$ Row ['keyword']}{$ Row ['author']}{$ Row ['addtime']}{$ Row ['content']}

Delete; // The "#" here is just a code name and will be replaced later. Because the addition and deletion operations are complicated, write an action. php file separately.

Modify;


Action. php:

// This is a page for adding, deleting, modifying, and querying data.

// 1. Import the configuration file

Require ("dbconfig. php ");

// 2. Connect to mysql and select a database

$ Link = @ mysql_connect (HOST, USER, PASS) or die ("database link failed ");

Mysql_select_db (DBNAME, $ link );

// 3. Determine the operation based on the value of action and execute the corresponding code

Switch ($ _ GET ["action"]) {

Case "add ":

// 1. obtain the information to be added and add other information

$ Tilte =$ _ POST ["title"];

$ Keywords = $ _ POST ["keywords"];

$ Author = $ _ POST ["author"];

$ Content = $ _ POST ["content"];

$ Addtime = time ();

// 2. Information Filtering

// 3. concatenate an SQL statement and perform the corresponding operation

$ SQL = insert into news value (null, '($ title)', '($ keywords)', '($ author)', $ addtime, '($ content) ');

Mysql_query ($ SQL, $ link );

// 4. Determine whether the request is successful

$ Id = mysql_insert_id ($ link );

If ($ id> 0 ){

Echo "news information added ";

}

Else {

Echo "failed to add news information ";

}

Echo ("return ");

Echo ("Browse News ");

Break;

Case "del ":

// 1. Obtain the news id to be deleted:

$ Id = $ _ GET ['id'];

// 2. Assemble and delete SQL statements and perform corresponding deletion operations

$ SQL = "delete from news where id = ($ id )";

Mysql_query ($ SQL, $ link );

// 3. automatically jump to the news browsing page after deletion

Header ("location: http://blog.csdn.net/q114942784/article/details/index.php ");

Break;

Case "update ":

// 1. Get the information to be modified
$ Title = $ _ POST ['title'];
$ Keywords = $ _ POST ['keyword'];
$ Author = $ _ POST ['author'];
$ Content = $ _ POST ['content'];
$ Id = $ _ POST ['id'];
// 2. filter the information to be modified (omitted here)
// 3. Assemble and modify the SQL statement and perform the Modification Operation
$ SQL = "update news set title =" ($ title) ", keywords = '($ keywords)', author = '($ author )', content = '($ content)' where id = ($ id )";
// Echo $ SQL;
Mysql_query ($ SQL, $ link );
// 4. Jump to the browsing interface
Header ("location: http://blog.csdn.net/q114942784/article/details/index.php ");

Break;

}

// 4. Close the database link

Mysql_close ("$ link ");

?>


Below is the page for adding news: http://blog.csdn.net/q114942784/article/details/add.php:


Publish news




Then the edit. php page is Edited:

// 1. Import the configuration file
Require ("dbconfig. php ");

// 2. Connect to mysql and select database
$ Link = @ mysql_connect (HOST, USER, PASS) or die ("database link failed ");
Mysql_select_db (DBNAME, $ link );
// 3. Obtain the id of the information to be modified, assemble and view the SQL statement, execute the query, and obtain the information to be modified.
$ SQL = "select * from news where id = {$ _ GET ['id']}";
$ Result = mysql_query ($ SQL, $ link );
// 4. Determine whether the information to be modified is obtained
If ($ result & mysql_num_rows ($ result)> 0 ){
$ News = mysql_fetch_assoc ($ result );
} Else {
Die ("No information found for modification ");
}

?>
Edit news


Finally, let's talk about how to replace the deleted and modified "#"

To be more user-friendly, use js Code to give a prompt

<Script type = "text/javascript">
Function dodel (id ){
If (confirm ("are you sure you want to delete it? ")){
Window. location = "action. php? Action = del & id = "+ id;
}
}
</Script>

Replace the first "#" with javascript: dodel ({$ row ["id "]})

The second "#", using edit. php? Replace id = {$ row ["id "]}

So far, a complete php news management system has been basically completed, and it will be improved tomorrow.




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.