This article describes a simple PHP implementation of the press release system. Share to everyone for your reference. Specifically as follows:
I small white, has been in the company with templates and framework to write PHP, found that sometimes even the basic SQL statements have forgotten, so there is a dream of the basic PHP review, consolidate under. Paging and searching, as well as sorting, haven't written yet, later continue to update ... (Code modification: Adding search and paging capabilities)
Articlepublish.html:
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"
"HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
< HTML lang= "en" >
articlepublishdo.php:
<?php
Header ("Content-type:text/html;charset=utf8");
Date_default_timezone_set (' Asia/shanghai ');
$title =trim ($_post[' title '));
$content =trim ($_post[' content '));
$time =date ("y-m-d h:i:s");
Require_once ' init.php ';
$sql = "INSERT into article (Title,content,create_time) VALUES (' $title ', ' $content ', ' $time ')";
echo $sql;
$re =mysql_query ($sql);//Execute SQL statement
if ($re) {
echo "publish successfully";
Echo ' <a href= "articlelist.php" > Return to the list of articles </a> ';
} else{
echo "Publish failed";
Echo ' <a href= "articlelist.php" > Return to the list of articles </a> ';
}
Mysql_close ()//Close Database
articlelist.php:
<!
DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
Articleedit.php:
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
articleupdate.php:
<?php
Header ("Content-type:text/html;charset=utf8");
$arr =$_post;
$id = (int) $arr [' id '];
Require_once ' init.php ';
$sql = "Update Article set title = ' $arr [title] ', content = ' $arr [content] ' WHERE id = ' $id '";
echo $sql;
$re =mysql_query ($sql);//Execute SQL statement
//echo $re;
if ($re) {
echo "modified successfully";
echo "<a href= ' articlelist.php ' > Return to Article List </a>";
} else{
echo "Modify failed";
echo "<a href= ' articlelist.php ' > Return to Article List </a>";
}
Mysql_close ()//Close Database
articledelete.php:
<?php
Header ("Content-type:text/html;charset=utf8");
Require_once ' init.php ';
$id = (int) $_get[' id '];
$sql = "Delete from article where id = ' $id '";
echo $sql;
$re =mysql_query ($sql);
if ($re) {
echo "delete succeeded";
echo "<a href= ' articlelist.php ' > Return to Article List </a>";
} else{
echo "Delete failed";
echo "<a href= ' articlelist.php ' > Return to Article List </a>";
}
init.php:
<?php
//Connection database
//Five step///Go to
Database add
article $conn =mysql_connect ("localhost", "root", "");//LINK Database
echo $conn;
$re =mysql_select_db ("article");//Select Database
mysql_query ("Set names UTF8");/set Interactive character set
Basic Knowledge Summary:
Article Publishing System
1.articlepublish.html Publish article page submit to articlepublishdo.php page, execute write to database
2.articlelist.php Articles List page
3. Click Edit, modify the article submit to aiticleedit.php form page (Echo)
4. Click Modify Article button to submit to articleupdate.php
I hope this article will help you with your PHP programming.