The PHP real-combat news management system uses the bootstrap framework

Source: Internet
Author: User
Tags define header include interface sql mysql net php file

Just in touch with PHP in the video to write a news management system which also used the bootstrap framework

Write it down and organize your thoughts.

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 ID of the news
-> title varchar () not null,//This is the headline of the News
-> keywords varchar () Not null,//This is the key word of the news
-> author varchar () not null,//This is the author of the News
-> addtime int unsigned not null,//This is the time to add news
-> content text not NULL);//This is the news.

In this way, the database table is built, and the following begins to write the page.

First wrote a database configuration file dbconfig.php:

Define (host, "localhost");//Host Name

Define (user, "root");//username

Define (pass, "");//password

Define (dbname, "newsdb");//Database name

?>

Then it's a menu.php file.






<title>Html5&bootstrap</title>

-->











    News management System
  • Browse News

  • Release 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= "Prettify-4-mar-2013/prettify.js" ></script>

After two simple work done above, it's time to do the homepage http://blog.csdn.net/q114942784/article/details/index.php:

First, import the navigation bar menu.php

Then add a title and a table.

Browse News







Require ("dbconfig.php");

2. Link MySQL, select database

$link = @mysql_connect (Host,user,pass) or Die ("Link Database error!") ");

mysql_select_db (dbname, $link);

3. Execute query, return 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 configuration file

"; "; "; "; "; "; "; "; "
News ID title Key Words author Time content Operation
{$row [' id ']}{$row [' Tilte ']}{$row [' keywords ']}{$row [' Author ']}{$row [' Addtime ']}{$row [' content ']}

The "#" here is just a code name, the back will replace it, because the additions and deletions of the operation is more complex, so write a separate action.php file

Modify


action.php:

This is a data to delete the deletion of the page to check

1. Import configuration file

Require ("dbconfig.php");

2. Link MySQL and select database

$link = @mysql_connect (Host,user,pass) or Die ("Database link failed");

mysql_select_db (dbname, $link);

3. According to the value of the action, to determine the operation, to execute the appropriate code

Switch ($_get["action"]) {

Case "Add":

1. Get the information you want to add, add additional information

$tilte =$_post["title"];

$keywords =$_post["keywords"];

$author =$_post["Author"];

$content =$_post["Content"];

$addtime =time ();

2. Filtering of information

3. Splicing the SQL statements and performing the appropriate actions

$sql =insert into News value (NULL, ' ($title) ', ' ($keywords) ', ' ($author) ', $addtime, ' ($content) ');

mysql_query ($sql, $link);

4. Determine whether the success

$id =mysql_insert_id ($link);

if ($id >0) {

echo "

News information added successfully

";

}

else{

echo "

News information added failed

";

}

Echo ("return");

Echo ("Browse News");

Break

Case "Del":

1. Get the news ID to delete:

$id =$_get[' id '];

2. Assemble and delete the SQL statements and perform the appropriate delete operations

$sql = "Delete from news where id= ($id)";

mysql_query ($sql, $link);

3. Automatically jump to the news browsing interface after deletion

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

Break

Case "Update":

1. Get the information you want to modify
$title = $_post[' title '];
$keywords = $_post[' keywords '];
$author = $_post[' author '];
$content = $_post[' content '];
$id = $_post[' id '];
2. Filter the information to be modified (omitted here)
3. Assemble and modify SQL statements and perform modification operations
$sql = "Update news set title=" ($title), keywords= ' ($keywords) ', author= ' ($author) ', content= ' ($content) ' where id= ($id )";
Echo $sql;
mysql_query ($sql, $link);
4. Jump to browse interface
Header ("location:http://blog.csdn.net/q114942784/article/details/index.php");

Break

}

4. Close the database link

Mysql_close ("$link");

?>


The following writes the page http://blog.csdn.net/q114942784/article/details/add.php file that adds the news:


Release News

























Title
Key words
Author
Content







Then is the edited page edit.php page:

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

2. Connect MySQL, select database
$link = @mysql_connect (Host,user,pass) or Die ("Database link failed");
mysql_select_db (dbname, $link);
3. Get the ID of the information you want to modify and assemble the SQL statement, execute the query, get the information to modify
$sql = "SELECT * from news where id={$_get[' id ']}";
$result =mysql_query ($sql, $link);
4. Determine if the information to be modified is obtained
if ($result && mysql_num_rows ($result) >0) {
$news =mysql_fetch_assoc ($result);
}else{
Die ("No information was found to be modified");
}

?>

Edit News
























Title
Key words
Author
Content <?php echo $news [' content '];?>






Finally, to mention, delete and modify the "#" with what to replace

Here for the humanization of some, with the JS code to give a hint

<script type= "Text/javascript" >
function Dodel (ID) {
if (Confirm (ok to delete)) {
window.location= "action.php?action=del&id=" +ID;
}
}
</script>

First "#", replace with Javascript:dodel ({$row ["id]}")

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

At this point, a complete PHP news management system is basically completed, tomorrow to improve.






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.