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:

<? 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

<! Doctype html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Meta name = "viewport" content = "width = device-width, initial-scale = 1.0">
<Title> HTML5 & BootStrap </title>
<Link href = "bootstrap-3.2.0-dist/css/bootstrap.css" rel = "stylesheet">
<! -- [If IE]>
<Script src = "http://html5shiv.googlecode.com/svn/trunk/html5.js"> </script>
<! [Endif] -->
<Link href = "prettify-4-Mar-2013/prettify.css" rel = "stylesheet">
<Link href = "style.css" rel = "stylesheet">
</Head>
<Body onLoad = "prettyPrint ()">
<Style>
Body {background: orange ;}
@ Media (max-width: 997px) {body {background: # 0FC ;}}
</Style>
<Div class = "container">
<Nav class = "navbar-default" role = "navigation">
<Div class = "container-fluid">
<! -- Collect the nav links, forms, and other content for toggling -->
<Div class = "collapse navbar-collapse" id = "bs-example-navbar-collapse-1">
<Ul class = "nav navbar-nav">
<H2> News Management System <Li> <a href = "index. php"> browse news </a> </li>
<Li> <a href = "add. php"> Publish news </a> </li>
<Hr>
</Ul>
</Div>
<! --/. Navbar-collapse -->
</Div>
<! --/. Container-fluid -->
</Nav>
</Div>
<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>
</Body>

</Html>

After completing the two simple steps above, you should compile index. php on the homepage:

First, import menu. php In the navigation bar.

<? Php include ("index. php");?>

Then add a title and a table.

<H3> browse news

<Table class = "table-hover">

<Tr>

<Th> News id </th>

<Th> title </th>

<Th> keyword </th>

<Th> author </th>

<Th> time </th>

<Th> content </th>

<Th> operation </th>

</Tr>

<? Php // five parts

// 1. Import the configuration file

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 "<tr> ";

Echo "<td >{$ row ['id']} </td> ";

Echo "<td >{$ row ['tilte ']} </td> ";

Echo "<td >{$ row ['keyword']} </td> ";

Echo "<td >{$ row ['autor']} </td> ";

Echo "<td >{$ row ['addtime']} </td> ";

Echo "<td >{$ row ['content']} </td> ";

Echo "<td>

<A href = '#'> Delete </a>; // The "#" here is only a code name, which will be replaced later. The addition and deletion operations are complex, therefore, write an action separately. PHP File

<A href = '#'> modify </a>;

</Td> ";

Echo "</tr>"

}

// 5. Release the result set

Mysql_free_result (& result );

Musql_close ($ link );

?>

</Table>


Action. php:

<? 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 "

}

Else {

Echo "

}

Echo ("<a href = 'javascript: window. history. back () '> return </a> ");

Echo ("<a href = 'index. php'> browse news </a> ");

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: 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: index. php ");

Break;

}

// 4. Close the database link

Mysql_close ("$ link ");

?>


Below is the add. php file on the page for adding news:

<? Php include ("menu. php"); // import the navigation bar?>
<H3 align = "center"> Publish news <Div class = "container">
<Form action = "action. php? Action = add "method =" post ">

<Table class = "table-bordered table-hover table-responsive">
<Tr>
<Td align = "center"> title </td>
<Td> <input class = "col-xs-10" type = "text" name = "title"> </td>
</Tr>
<Tr>
<Td align = "center"> keywords </td>
<Td> <input class = "col-xs-10" type = "text" name = "keywords"> </td>
</Tr>
<Tr>
<Td align = "center"> author </td>
<Td> <input class = "col-xs-10" type = "text" name = "author"> </td>
</Tr>
<Tr>
<Td valign = "top" align = "center"> content </td>
<Td> <textarea class = "col-xs-10" name = "content"> </textarea> </td>
</Tr>
<Tr>
<Td colspan = 2 align = "center">
<Input class = "btn-primary" type = "submit" value = "add">
<Input class = "btn-primary" type = "reset" value = "reset">
</Td>
</Tr>
</Table>
</Form>
</Div>


Then the edit. php page is Edited:

<? Php include ("menu. php"); // import the navigation bar
// 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 ");
}

?>
<H3 align = "center"> edit news <Form action = "action. php? Action = update "method =" post ">
<Input type = "hidden" name = "id" value = "<? Php echo $ news ['id'];?> ">
<Table class = "table-bordered table-hover table-responsive">
<Tr>
<Td align = "center"> title </td>
<Td> <input class = "col-xs-10" type = "text" name = "title" value = "<? Php echo $ news ['title'];?> "> </Td>
</Tr>
<Tr>
<Td align = "center"> keywords </td>
<Td> <input class = "col-xs-10" type = "text" name = "keywords" value = "<? Php echo $ news ['keyword'];?> "> </Td>
</Tr>
<Tr>
<Td align = "center"> author </td>
<Td> <input class = "col-xs-10" type = "text" name = "author" value = "<? Php echo $ news ['author'];?> "> </Td>
</Tr>
<Tr>
<Td valign = "top" align = "center"> content </td>
<Td> <textarea class = "col-xs-10" name = "content"> <? Php echo $ news ['content'];?> </Textarea> </td>
</Tr>
<Tr>
<Td colspan = 2 align = "center">
<Input class = "btn-primary" type = "submit" value = "edit">
<Input class = "btn-primary" type = "reset" value = "reset">
</Td>
</Tr>
</Table>
</Form>


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.





Is there a Simple cms news management system? Php

Php and dede can all be used, and a 08cms is recommended, but this is relatively free, professional and complicated. The two new years may not be suitable for you, but you can also check it.

A streamlined PHP news management system CMS

Kingcms

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.