PHP + MySQL implement simple message board function

Source: Internet
Author: User
The message board is based on the function of adding, managing, modifying, and deleting data. let's take a look at a simple message board example in PHP + MySQL. I hope the article will help you. You can add, delete, modify, and query simple blogs implemented by php + mysql ....

The message board is based on the function of adding, managing, modifying, and deleting data. let's take a look at a simple message board example in PHP + MySQL. I hope the article will help you.

You can add, delete, modify, and query a simple blog implemented by php + mysql. The effect is as follows:

I. database and table structure

Database: test

Table: micro_blog (only one table) field: id, title, date, content, hits

The table structure is as follows:

Create table 'micro _ blog '(
'Id' int (20) unsigned not null AUTO_INCREMENT,
'Title' text not null,
'Content' longtext not null,
'Date' datetime not null default '2017-00-00 00:00:00 ',
'Hits 'int (20) DEFAULT 0,
Primary key ('id ')
) ENGINE = MyISAM default charset = utf8;

II. files

File description

File description
Default. php default homepage. Display the blog post and Operation connection.
Add. php adds function modules for new blog posts.
Edit. php modifies the added blog posts.
Delete. php deletes the blog module.
View. php displays the details of a blog post (title | add date | browsing times | content ).
Conn. php links to the database. It is referenced in other files.
Conn. php

// Connect to the MySql database service
$ Conn = @ mysql_connect ("localhost: 3306", "root", "www.361way.com") or die ("An error occurred while connecting to the database server! ");
// Connect to the ly_php_base database
@ Mysql_select_db ("test", $ conn) or die ("failed to connect to database! ");
Mysql_query ("set names 'utf8 '");
?>
Note: In the subsequent set names utf8, if not executed, Chinese characters inserted into the database will become garbled characters.

Default. php

Include ("conn. php ");
// Manage search keywords
If (! Empty ($ _ GET ['Keys ']) {
$ Keys = "WHERE title like '%". $ _ GET ['Keys']. "% '";
} Else {
$ Keys = "";
}
$ SQL = "SELECT * FROM micro_blog". $ keys. "ORDER BY id DESC LIMIT 10 ";
$ Query = mysql_query ($ SQL );
$ Rs = mysql_fetch_array ($ query );
?>



My blog homepage



Add content


If (! $ Rs ){
Echo "no related content! ";
}
// The paging navigation function is not implemented
While ($ rs ){
?>
Title: | "> Edit |"> Delete
  • Date:

  • Content ... "> | View details |



    $ Rs = mysql_fetch_array ($ query );
    }
    ?>



    Add. php

    // Introduce the database connection file
    Include ("conn. php ");
    If (! Empty ($ _ POST ['submit ']) {
    $ Title = $ _ POST ['title'];
    $ Content = $ _ POST ['content'];
    $ SQL = "INSERT INTO micro_blog VALUES (NUll, '$ title',' $ content', now (), 0 )";
    Mysql_query ($ SQL );
    }
    ?>





    Publish Weibo page


    View content




    Edit. php

    Include ("conn. php ");
    If (! Empty ($ _ GET ['id']) {
    $ Id = $ _ GET ['id'];
    $ SQL = "select * from micro_blog where id =". $ _ GET ['id'];
    $ Query = mysql_query ($ SQL );
    $ Rc = mysql_fetch_array ($ query );
    }
    If (! Empty ($ _ POST ['update']) {
    Echo "the update button is submitted successfully! ";
    }
    ?>




    Edit page




    Delete. php

    Include ("conn. php ");
    If (! Empty ($ _ GET ['id']) {
    Mysql_query ("delete from micro_blog where id =". $ _ GET ['id']);
    } Else {
    Echo "parameter introduction failed! ";
    }
    ?>




    <? Php echo $ rc ['title'];?> | My blog


    Back to homepage








  • View. php

    Include ("conn. php ");
    If (! Empty ($ _ GET ['id']) {
    $ SQL = "SELECT * FROM micro_blog WHERE id =". $ _ GET ['id'];
    $ Rc = mysql_fetch_array (mysql_query ($ SQL ));
    Mysql_query ("UPDATE micro_blog SET hits = hits + 1 WHERE id =". $ _ GET ['id']);
    } Else {
    Echo "parameter introduction failed! ";
    }
    ?>





    <? Php echo $ rc ['title'];?> | My blog


    Back to homepage








  • 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.