Home>Article>Backend Development> PHP implements simple message board function (source code attached)

PHP implements simple message board function (source code attached)

烟雨青岚
烟雨青岚 forward
2020-06-09 09:48:23 10672browse

PHP implements simple message board function (source code attached)

php implements simple message board function

1. Principle

Simply put, it means creating the database, adding data, and displaying it on the front end. My program is simply to leave a message and then display it.

First write the front-end page of the message, and simply write the author, title and content.

2. Interface:

PHP implements simple message board function (source code attached)

3. Interface to display messages:

PHP implements simple message board function (source code attached)

4. Code

(1) Page to add a message

    留言    

留言板

标题
作者
内容

(2) Background processing of messages, storing the author, title, and content into the built database

error; } if($con->select_db("messageboard")){ echo $con->error; } if($con->query("SET NAMES utf8")){ echo $con->error; } $id=$_POST["id"]; $title=$_POST["title"]; $author=$_POST["author"]; $message=$_POST["message"]; $time=date('y-m-d h:m:s'); $sql="insert into messageboard(id,title,author,message,dateline) values('$id','$title','$author','$message','$time')"; if($str=$con->query($sql)){ echo ""; } else { echo ""; } ?>

(3) The following is the page code for displaying messages

error; } if($con->select_db("messageboard")){ echo $con->error; } if($con->query("SET NAMES utf8")){ echo $con->error; } $sql="select * from messageboard ORDER BY dateline DESC "; $str=$con->query($sql); if($str && mysqli_num_rows($str)){ while($row= mysqli_fetch_assoc($str)){ $data[]=$row; } } ?>     留言板    
标题
作者
内容

5. Problems encountered

The data cannot be displayed on the display page at the beginning. After searching for a long time, it turned out that the wrong query was written in the sql. The method is written as:

select * from message where dateline desc;

You must use where to query it if there are conditions. For example:

select * from message where dateline=$date;

Because my program does not transfer data to this from the previous page, I can only use the following method to sort and list all the data by time.

select * from message order by dateline;

Thank you for reading. Please point out any shortcomings in the above code. I hope you can gain something.

This article is reproduced from: https://blog.csdn.net/jeak2015/article/details/53440522

Recommended tutorial: "PHP Tutorial"

The above is the detailed content of PHP implements simple message board function (source code attached). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete