PHP to implement simple news release System Instance _php skills

Source: Internet
Author: User
Tags character set php form php programming

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.

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.