Home > Article > Backend Development > How to implement a simple message board in php
How to implement a simple message board in php: 1. Create two tables in the database; 2. Write the send page and message page; 3. Implement user login through session; 4. Create a logout login page.
The operating environment of this article: Windows 7 system, PHP version 7.4, Dell G3 computer.
How to implement a simple message board in php?
PHP MySql implements a simple message board:
//Well, I learned from the book. I didn’t write the code myself, but I can understand it. I have time to write a better-looking one by myself~ (It took me a day if I am not skilled...
Message board is the basis for contact with WEB development. To write a message board, you need to know some basic tags on the front end. The database has a basic understanding of SQL language, basic knowledge of PHP, basic database basics and PHP basics => message board.
The front is high energy wow (the interface is really confusing...
First Build a database. There are two tables in the database, one to store account passwords, and one to store message information.
//创建数据库,里面有两张表Admin和Message create database gbook; //创建Admin表,记录用户名和密码 create table admin( username varchar(20) not null, userpass varchar(20) not null ); //创建Message表,记录留言的id,留言人,留言日期,留言内容以及回复 create table message( id int(4) not null auto_increment primary key, author varchar(20) not null, addtime datetime not null, content varchar(1000) not null, reply varchar(1000) not null );
First implement the user message part. This is the first step. If there is no message, the index page will be empty~
"; else { echo "bad!
"; } mysqli_select_db($link,"gbook");//选择数据库 $insert = "insert into message(author,addtime,content,reply) values('$name','$addtime','$content','')"; mysqli_query($link,$insert); mysqli_close($link); echo ""; } mysqli_close($link); ?>欢迎来到陈雨情的留言本吼吼吼
欢迎来到×××的留言本吼吼吼 |
[我要写留言] [管理留言] |
版权所有:Vmorish E-mail:vmorish@163.com |
Effect:
Then you can go to the main page
欢迎来到陈雨情的留言本吼吼吼
欢迎来到×××的留言本吼吼吼 |
[我要写留言] [管理留言] |
";
$datanum = mysqli_num_rows($result);
echo "共有".$totalnum."条留言,每页".$pagesize."条,共".$totalpage."页。 "; //输出页码 for( $i = 1; $i <= $totalpage; $i++){ echo "[".$i."] "; } echo " "; //从message表中查询当前页面所要显示的留言,并根据时间排序 $query = "select * from message order by addtime desc limit $begin,$pagesize"; $result = mysqli_query($link,$query); $datanum = mysqli_num_rows($result); //循环输出所有留言,如果管理员已经回复则同时输出回复 for( $i = 1; $i <= $datanum; $i++){//$datanum??? $info = mysqli_fetch_array($result); echo "->[".$info['author']."]于".$info['addtime']."说: "; echo " ".$info['content']." "; if( $info['reply'] != ""){ // 显示粗体 echo "管理员回复:".$info['reply']." "; } echo " "; }//else结束 echo " |
Effect:
Then the administrator logs in
"; }else{ $info = mysqli_fetch_array($result); if( $info['userpass'] != $password){ echo "密码输入错误,请重新登录!
"; }else{ //如果用户名密码都正确,则注册一个session来标记其登录状态 echo "hhhh
"; session_start(); // $_SESSION["login"] = "YES"; echo ""; } } mysqli_close($link); } ?>欢迎来到陈雨情的留言本吼吼吼
欢迎来到×××的留言本吼吼吼 |
[我要写留言] [管理留言] |
版权所有:Vmorish E-mail:vmorish@163.com |
Effect:
778ac6ed3ed4dd141640aaf612719100 9ef252f54a127e5e87adb5bbb0d50cd0回首页5db79b134e9f6b82c0b36e0489ee08ed]"; exit; ?>Recommended study: "
PHP Video Tutorial 》
The above is the detailed content of How to implement a simple message board in php. For more information, please follow other related articles on the PHP Chinese website!