Home php教程 php手册 PHP+MySQL实现简单留言板功能

PHP+MySQL实现简单留言板功能

May 22, 2016 pm 06:38 PM
iconv include select substr textarea Pagination

留言板基于功能就是数据添加管理修改及数据删除功能了,下面我们就来看一个PHP+MySQL实现简单留言板例子,希望文章能够帮助到大家。

通过php+mysql 实现的简易blog,可以实现增删改查。效果如下图:

micro_blog

一、数据库及表结构

数据库:test

表:micro_blog(仅仅有一个表)字段:id,title,date,content,hits

表结构如下:

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 '0000-00-00 00:00:00',
  `hits` int(20) DEFAULT 0,
   PRIMARY KEY (`ID`)
)ENGINE=MyISAM DEFAULT CHARSET=utf8;

二、文件

文件详细描述

文件  描述
default.php  默认主页。显示博文与操作连接。
add.php  添加新博文的功能模块。
edit.php  对已经添加过的博文进行修改操作。
delete.php  删除博文模块。
view.php  显示博文的详细信息(标题|添加日期|浏览次数|内容)。
conn.php  链接数据库操作。在其它文件中被引用。
conn.php

//连接MySql数据库服务
$conn = @mysql_connect("localhost:3306","root","www.361way.com") or die("连接数据库服务器失败!");
//连接ly_php_base数据库
@mysql_select_db("test",$conn) or die("未能连接到数据库!");
mysql_query("SET NAMES 'UTF8'");
?> 
注:后面的set names utf8,如果不执行,会出现插入数据库中的汉字会变成乱码。

default.php

include("conn.php");
//搜索关键字的管理
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);
?>



我的微博客主页



添加内容

 
 



if(!$rs){
    echo "没有相关内容!";
}
//没有实现分页导航功能
while($rs){
?>

标题:|编辑|删除


  • 日期:

  • 内容...... |查看详细内容|




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


     
    add.php

    //引入连接数据库文件
    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);
    }
    ?>





    发布微博页面


    查看内容



      标题:
     
     

      内容:
     
     

     
     



     

    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 "更新按钮提交成功!";
    }
    ?>




    编辑页面



      标题:
     
     

      内容:
     
     

     
     



     

    delete.php

    include("conn.php");
    if(!empty($_GET['id'])){
                mysql_query("delete from micro_blog where id =".$_GET['id']);
    } else {
            echo "参数引入失败!";
    }
    ?>




    <?php echo $rc['title'];?>|我的微博客


    返回主页面



     





  •  

    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 "参数引入失败!";
    }
    ?>





    <?php echo $rc['title'];?>|我的微博客


    返回主页面



     





  •  
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    PHP development: How to implement table data sorting and paging functions PHP development: How to implement table data sorting and paging functions Sep 20, 2023 am 11:28 AM

    PHP development: How to implement table data sorting and paging functions In web development, processing large amounts of data is a common task. For tables that need to display a large amount of data, it is usually necessary to implement data sorting and paging functions to provide a good user experience and optimize system performance. This article will introduce how to use PHP to implement the sorting and paging functions of table data, and give specific code examples. The sorting function implements the sorting function in the table, allowing users to sort in ascending or descending order according to different fields. The following is an implementation form

    How to use JavaScript to implement table paging function? How to use JavaScript to implement table paging function? Oct 20, 2023 pm 06:19 PM

    How to use JavaScript to implement table paging function? With the development of the Internet, more and more websites use tables to display data. In some cases where the amount of data is large, the data needs to be displayed in pages to improve user experience. This article will introduce how to use JavaScript to implement table paging function and provide specific code examples. 1. HTML structure First, we need to prepare an HTML structure to host tables and paging buttons. We can use &lt;tab

    Recommended essential functions for Chinese processing: Detailed explanation of PHP iconv function Recommended essential functions for Chinese processing: Detailed explanation of PHP iconv function Jun 27, 2023 pm 02:04 PM

    In the process of text processing, it is a common requirement to convert strings in different encoding formats. The iconv (InternationalizationConversion) function provided in the PHP language can meet this need very conveniently. This article will introduce the use of iconv function in detail from the following aspects: Definition of iconv function and introduction to common parameters Example demonstration: Convert GBK encoded string to UTF-8 encoded string Example demonstration: Convert UTF

    Asynchronous processing method of Select Channels Go concurrent programming using golang Asynchronous processing method of Select Channels Go concurrent programming using golang Sep 28, 2023 pm 05:27 PM

    Asynchronous processing method of SelectChannelsGo concurrent programming using golang Introduction: Concurrent programming is an important area in modern software development, which can effectively improve the performance and responsiveness of applications. In the Go language, concurrent programming can be implemented simply and efficiently using Channels and Select statements. This article will introduce how to use golang for asynchronous processing methods of SelectChannelsGo concurrent programming, and provide specific

    How to hide the select element in jquery How to hide the select element in jquery Aug 15, 2023 pm 01:56 PM

    How to hide the select element in jquery: 1. hide() method, introduce the jQuery library into the HTML page, you can use different selectors to hide the select element, the ID selector replaces the selectId with the ID of the select element you actually use; 2. css() method, use the ID selector to select the select element that needs to be hidden, use the css() method to set the display attribute to none, and replace selectId with the ID of the select element.

    Detailed explanation of the principle of MyBatis paging plug-in Detailed explanation of the principle of MyBatis paging plug-in Feb 22, 2024 pm 03:42 PM

    MyBatis is an excellent persistence layer framework. It supports database operations based on XML and annotations. It is simple and easy to use. It also provides a rich plug-in mechanism. Among them, the paging plug-in is one of the more frequently used plug-ins. This article will delve into the principles of the MyBatis paging plug-in and illustrate it with specific code examples. 1. Paging plug-in principle MyBatis itself does not provide native paging function, but you can use plug-ins to implement paging queries. The principle of paging plug-in is mainly to intercept MyBatis

    How to use Layui to develop a data display page with paging function How to use Layui to develop a data display page with paging function Oct 24, 2023 pm 01:10 PM

    How to use Layui to develop a data display page with paging function Layui is a lightweight front-end UI framework that provides simple and beautiful interface components and a rich interactive experience. During development, we often encounter situations where we need to display large amounts of data and perform paging. The following is an example of a data display page with paging function developed using Layui. First, we need to introduce Layui related files and dependencies. Add the following code to the &lt;head&gt; tag of the html page

    Vue component practice: paging component development Vue component practice: paging component development Nov 24, 2023 am 08:56 AM

    Vue component practice: Introduction to paging component development In web applications, the paging function is an essential component. A good paging component should be simple and clear in presentation, rich in functions, and easy to integrate and use. In this article, we will introduce how to use the Vue.js framework to develop a highly customizable paging component. We will explain in detail how to develop using Vue components through code examples. Technology stack Vue.js2.xJavaScript (ES6) HTML5 and CSS3 development environment

    See all articles