Basic example of PHP: Use PHP + Mysql to compile a simple news management system and mysql news management system

Source: Internet
Author: User

Basic example of PHP: Use PHP + Mysql to compile a simple news management system and mysql news management system

Goal: Use php and mysql operation functions to publish, browse, modify, and delete news information.

Steps:

I. create databases and tables

1. Create a database and a table: newsdb

2. Create a table: news

Field: News id, title, keyword, author, release time, news content

2. Create a PHP file and write code (The following shows the PHP file to be created and its usage)

Dbconfig. php public configuration file, database connection configuration information

Menu. php public navigation bar

Index. php views news files (this is the homepage)

Add. php releases a single news Table Page

Edit. php edit a single news Table Page

Action. php: the action of adding, modifying, and deleting news information (in the background)

**************************************** ******************************

The following statements are used to create a database:

1 create database newsdb; // create database Statement 2 create table news (3 id int unsigned not null auto_increment primary key, 4 title varchar (64) not null, 5 keywords varchar (64) not null, 6 author varchar (16) not null, 7 addtime int unsigned not null, 8 content text not null9); // Create a table statementDatabase creation statement

**************************************** *******************************

The following is the dbconfig. php file code

1 <? Php2 // public information configuration 3 // database configuration information 4 define ("HOST", "localhost"); // HOST name 5 define ("USER", "root "); // account 6 define ("PASS", "root"); // password 7 define ("DBNAME", "newsdb"); // database name 8?>

The following is the menu. php file code (the page to be browsed at the beginning. The index page is the main page after news is added)

1 

The code for the add. php file is as follows (add specific code)

1 The code for the action. php file is as follows (add, delete, modify, and implement code)

1 <? Php 2 // This is a page for adding, deleting, and modifying information. 3 4 // 1. import the configuration file 5 require ("dbconfig. php "); 6 // 2. connect to MYSQL and select database 7 $ link = @ mysql_connect (HOST, USER, PASS) or die ("database connection failed! "); 8 mysql_select_db (DBNAME, $ link); 9 10 // 3. determine the operation according to the required action value, and execute the corresponding code 11 switch ($ _ GET ["action"]) 12 {13 case "add ": // perform the add operation. 14 // 1. obtain the information to be added and add other information. 15 $ title =$ _ POST ["title"]; 16 $ keywords =$ _ POST ["keywords"]; 17 $ author = $ _ POST ["author"]; 18 $ content = $ _ POST ["content"]; 19 $ addtime = time (); 20 // 2. seat Information Filtering (Omitted) 21 // 3. assemble and add SQL statements, and execute the Add Operation 22 $ SQL = "insert into news values (null, '{$ title}', '{$ keywords }','{ $ Author} ',' {$ addtime} ',' {$ content} ') "; 23 mysql_query ($ SQL, $ link); 24 // 4. judge whether the request is successful 25 $ id = mysql_insert_id ($ link); // obtain the self-incrementing idnumber 26 if ($ id> 0) of the information just added) 27 {28 echo "The following is the index. php file code (this page views news and adds, deletes, and modifies news information)

1 The edit. php file code is as follows (edit the specific code)

1  

Related Article

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.