PHP implements simple message board function (source code attached)

烟雨青岚
Release: 2023-04-08 19:58:01
forward
10671 people have browsed it

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

    留言    

留言板

标题
作者
内容
Copy after login

(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 ""; } ?>
Copy after login

(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; } } ?>     留言板    
标题
作者
内容
Copy after login

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;
Copy after login

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

select * from message where dateline=$date;
Copy after login

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;
Copy after login

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!

Related labels:
source:csdn.net
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!