Simple article publishing system--background management system

Source: Internet
Author: User
Tags button type reserved
From the Learning network to establish a simple article publishing system-background management system, features include the publication of articles, view the list of articles, which also provides the deletion and modification of the article function. First use MySQL to build database info, in the info database to create a article table:
The directory structure of the article publishing system is as follows:
In order to realize operation database function, need to do the PHP connection database operation, so first encapsulates these operations, when needs to operate the database, will introduce the file. Configuration of the database config.php
<?php
	//Prevent garbled
	header ("Content-type:text/html;charset=utf-8");
	Define (' HOST ', ' 127.0.0.1 ');
	Define (' USERNAME ', ' root ');
	Define (' PASSWORD ', ' root ');
? >
Connect database and other operations connect.php
<?php
	require_once (' config.php ');

	File Head settings
	error_reporting (E_all &~e_notice &~e_deprecated);

	1. Even library
	if (!) ( $con = mysql_connect (Host,username,password))) {
		echo mysql_error ();
	}
	2. Select
	the Library if (!mysql_select_db ("info")) {
		echo mysql_error ();
	}
	3. Character Set
	if (!mysql_query ("Set Names UTF8")) {
		echo mysql_error ()
	}
? >


The following first implementation of the function of publishing articles, using to bootstrap to build a simple page article.add.php, the effect is as follows:
Mycss/style.css
Body {
	font-family: ' Hiragino Sans GB ', ' Microsoft Yahei ', Wenquanyi Micro Hei, Simsun,tahoma,arial,helvetica, Stheiti;

	/* Background-color: #BDC3C7; *
/} textarea {
	Resize:none
}

. Title {
	padding-left:30px;
}

. Body-container {
	/* BORDER-RADIUS:8PX;
	
	padding:20px;
	box-shadow:0 0 1px 1px #DDD; * *

	margin-bottom:80px;
}

. Copyright {
	Background-color: #BDC3C7;
	Text-align:center;
	padding:20px;

	position:fixed;
	bottom:0px;
	width:100%;
}
article.add.php
<! DOCTYPE html>         When the article is completed, you need to submit the article information (that is, submit the form), need a handler for the database to add operations, the corresponding file is article.add.handle.php, add the article information, and return information to the browser, display the status of the post (success or failure), and jump to the article's management page (article list) article.manage.php.        article.add.handle.php
<?php
	require_once ('.. /connect.php ');
	Pass over the information into the warehouse, before the storage of all the information to verify.
	//print_r ($_post);

	if (!isset ($_post[' title ')) | | | empty ($_post[' title ')) {
		echo <script>alert (' title cannot be empty '); window.location.href= ' article.add.php ' </script>;
	}

	$title = $_post[' title '];
	$author = $_post[' author '];
	$description = $_post[' description '];
	$content = $_post[' content '];
	$dateline = time ();

	$insertsql = "INSERT into article (Title,author,description,content,dateline) VALUES (' $title ', ' $author ', ' $ Description ', ' $content ', $dateline) ';
	echo $insertsql;
	if (mysql_query ($insertsql)) {
		echo "<script>alert (" success in publishing the article) "; window.location.href= ' article.manage.php ' </script>;	
	} else {
		echo ' <script>alert (' Publish article failed '); window.location.href= ' article.manage.php ' </script>;
	}

	Mysql_close ($con);
? >

The article.manage.php interface is as follows:

        to deal with the deletion and modification of the article, we need to establish the corresponding PHP processing files: article.del.handle.php, article.modify.handle.php. At the same time there is a need for the article Information interface article.modify.handle.php.        article.manage.php (need to search the database, get all article information)
<?php require_once ('..
	/connect.php ');
	$sql = "SELECT * from article ORDER by dateline DESC";
	$query = mysql_query ($sql);
		if ($query && mysql_num_rows ($query)) {while ($row = Mysql_fetch_assoc ($query)) {$data [] = $row;
	} else {$data = array (); }?> <! DOCTYPE html> Click "Delete", the corresponding article will be deleted, delete operation submitted to the article.del.handle.php file for processing. article.del.handle.php
<?php
	require_once ('.. /connect.php ');

	$id = Intval ($_get[' id '));
	$deletesql = "Delete from article where id= $id";
	if (mysql_query ($deletesql)) {
		echo <script>alert (' delete article succeeded '); window.location.href= ' article.manage.php ' </script>;
	} else {
		echo ' <script>alert (' delete article failed '); window.location.href= ' article.manage.php ' </script>;
	}
? >
After completing the delete operation (whether the deletion succeeds or the deletion fails), jump to the original article management interface article.manage.php. Click "Modify", will pass the corresponding article "id" to modify the page article.modify.php.        When the page receives an article ID, it queries the article based on the ID, and displays the article information in a text box for the administrator to modify. Click on the article ID 6 to modify:
Jump Modify Interface:
article.modify.php
<?php require_once ('..
	/connect.php ');
	Read old information $id = Intval ($_get[' id '));
	$query = mysql_query ("SELECT * from article where id= $id"); $data = Mysql_fetch_assoc ($query);?> <! DOCTYPE html> Submit a change request to article.modify.handle.php for an update of the article.

article.modify.handle.php

<?php
	require_once ('.. /connect.php ');
	Pass over the information into the warehouse, before the storage of all the information to verify.
	//print_r ($_post);

	if (!isset ($_post[' title ')) | | | empty ($_post[' title ')) {
		echo <script>alert (' title cannot be empty '); Window.history.go ( -1);</script> ";
		Mysql_close ($con);
		Exit;
	}

	$id = $_post[' id '];
	$title = $_post[' title '];
	$author = $_post[' author '];
	$description = $_post[' description '];
	$content = $_post[' content '];
	$dateline = time ();

	$updatesql = "Update Article set title = ' $title ', author = ' $author ', description = ' $description ', content = ' $content ', dat Eline= $dateline where id= $id ";
	echo $updatesql;
	
	if (mysql_query ($updatesql) && mysql_affected_rows ($con)) {
		echo "<script>alert (" successful modification of the article "); window.location.href= ' article.manage.php ' </script>;	
	} else {
		echo ' <script>alert (' modify article failed '); window.location.href= ' article.manage.php ' </script>;
	}

	Mysql_close ($con);
? >

After clicking Submit "Modify", the modification succeeds:


After completing the modification (whether the modification succeeds or the modification fails), jump to the original article management interface article.manage.php.

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.