蝙蝠岛资源网 Design By www.hbtsch.com
                                本文实例讲述了PHP实现基本留言板功能的方法。分享给大家供大家参考,具体如下:
作为一个PHP的初学者,我试着写了一个留言板,页面有点丑,多多见谅,嘻嘻嘻
#我们写留言板需要用到数据库,所以我们先要建立三个表
user表

friend表

text表

#首先需要写一个注册与登录
##注册
zhuce.html
<meta charset="utf-8"> <title>zhuce</title> </head> <body> <form method="POST" action="zhuce.php"> <div style="margin-left: 500px;margin-top:200px;height: 250px;width: 250px"> <h1>用户注册页面</h1> 用户名:<input type="text" name="username"> <div>密   码:<input type="password" name="password"> <div><input type="submit" name="submit" value="注册"></div> </div> </form> </body>
zhuce.php
<"Content-type: text/html; charset=utf-8"); //处理数据库用户名乱码
$user=$_POST["username"];
$pwd=$_POST["password"];
if($user==""||$pwd=="")
	 {
   	echo "<script>alert('请确认信息完整性!'); history.go(-1);</script>"; 
	 }
else 
  	{
	 		
 			$link=mysqli_connect("localhost","root","","liuyan");//连接数据库
	 		mysqli_query($link,"set names utf8"); 
	 		$sql="select username from user where username='$_POST[username]'";
    	$result=mysqli_query($link,$sql);//执行sql语句
     	$num=mysqli_num_rows($result);//统计执行结果影响的行数
     	if($num)//如果存在该用户
     		{
     			echo "<script>alert('用户名已存在!'); history.go(-1);</script>"; 
    		}
      else//注册新用户
    		 { 
     			$sql_insert="insert into user (username,password)values('$_POST[username]','$_POST[password]')";
     			$res_insert=mysqli_query($link,$sql_insert);
     			if($res_insert)
     			{
     				echo "<script>alert('注册成功!');window.location='denglu.html';</script>"; 
     			}
     			else
     			{
     				echo "<script>alert('系统繁忙请重试!'); history.go(-1);</script>"; 
     			}
     	  }
  }
 "在这里插入图片描述" src="/UploadFiles/2021-04-02/202003260903334.png">
##登录
denglu.html
<head>
<meta charset="utf-8">
<title>denglu</title>
</head>
<body>
<form method="POST" action="denglu.php">
<div style="margin-left: 500px;margin-top:200px;height: 250px;width: 250px">
<h1>用户登录页面</h1>
用户名:<input type="text" name="username">
<div>密   码:<input type="password" name="password"></div><br/>
<input type="submit" name="submit" value="登录"> 
<a href="zhuce.html" rel="external nofollow" >注册</a> 
 </div>
</form>
</body>
denglu.php
<"username"];
	$_SESSION["uesrname"]=$user;//session超全局变量
	$pwd=$_POST["password"];//获取密码
	if($user=""||$pwd="")
	{
   echo "<script>alert('请输入用户名或密码!'); history.go(-1);</script>"; 
	}
	else
	{
		$link=mysqli_connect("localhost","root","","liuyan");//连接数据库
    mysqli_query($link,"set names utf8"); 
    $sql = "select username,password from user where username = '$_POST[username]' and password = '$_POST[password]'"; 
		$result=mysqli_query($link,$sql);//执行sql语句
		$num=mysqli_num_rows($result);//统计影响结果行数,作为判断条件
		if($num)
		{
			echo "<script>alert('登录成功!');window.location='003.php';</script>";//登录成功页面跳转 
		}
		else
		{
			echo "<script>alert('用户名或密码不正确!');history.go(-1);</script>"; 
	  }
	}
"在这里插入图片描述" src="/UploadFiles/2021-04-02/202003260903335.png">
#下面需要我们写一个登录进去的页面,它显示别人给你发来的留言以及进入你要给别人留言的页面或者退出系统,在这里我将html代码嵌入php
php代码如下
003.php
<"username"]=$user;
$username=$_SESSION["uesrname"];
$user1=implode("",$_SESSION);//将session中的数组变为字符串元素
$link=mysqli_connect("localhost","root","","liuyan");//连接数据库
mysqli_query($link,"set names utf8"); 
$sql="select * from text where recever='{$username}'";
$result=mysqli_query($link,$sql);//执行语句
if($num=mysqli_num_rows($result))//将HTML嵌入PHP中,实现从数据库中获得留言信息
{"utf-8">
</head>
 <body>
 <div>
 	<a href="fabu.html" rel="external nofollow" >发布信息</a>      
 	<a href="tuichu.php" rel="external nofollow" >退出系统</a></h3></div>
 	<br/><br/>
 	
 	<h2>留言信息:</h2>
 	<table cellpadding="0" cellspacing="0" border="1" width="60%">
<tr bgcolor="#8BBCC7">
	<td>发送人</td>
	<td>接收人</td>
	<td>发送时间</td>
	<td>信息内容</td>
	<"#FFFFFF">
	<td ><"在这里插入图片描述" src="/UploadFiles/2021-04-02/202003260903336.png">
#接下来我们就该写发布的页面以及PHP代码了
fabu.html
<head>
	<meta charset="utf-8">
	<title>fabu</title>
</head>
<body>
 <form method="POST" action="fabu.php">
<h1>发布信息<h1>
<a href="003.php" rel="external nofollow" >主页面</a>
<div>接收人:<input type="text" name="recever">
</select>
</div>
</select>
</div>
<br/>
<div>
	信息内容:<textarea input type="text" name="neirong"></textarea>
</div><br/>
<input type="submit" value="发送">
</form>
fabu.php
<"Content-type: text/html; charset=utf-8");
global $user;
$re=$_POST["recever"];//获取recever
$comment=$_POST["neirong"];//获取留言
@date_default_timezone_set(PRC);//将数组变为字符串函数
$time=date("Y-m-d G:i:s");//获取时间,G为24小时制
$_SESSION["username"]=$user;//开启session
$user1=implode("",$_SESSION);//将数组转为字符串
$link=mysqli_connect("localhost","root","","liuyan");//连接数据库
mysqli_query($link,"set names utf8"); 
$sql="insert into text(sender,recever,comment,time) values('$user1','$re','$comment','$time')";
$result=mysqli_query($link,$sql);//执行语句
$sql1="insert into friend(me,friend) values('$user1','$re')";//将me,friend存入数据库
$result=mysqli_query($link,$sql1);//执行语句
if($recever=""||$comment="")
{
	echo "<script>alert('发布失败!');window.location='fabu.html';</script>";
}
else
{
	echo "<script>alert('发布成功!');window.location='fabu.html';</script>";
}
"在这里插入图片描述" src="/UploadFiles/2021-04-02/202003260903337.png">
#最后是退出系统
<"uesrname"]);
echo "<script>alert('退出成功!');window.location='denglu.html';</script>"; 
"在这里插入图片描述" src="/UploadFiles/2021-04-02/202003260903338.png">
更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP+MySQL留言板开发专题》、《php缓存技术总结》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《PHP错误与异常处理方法总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
                                
                                
                                
                                    标签:
                                        PHP,留言板
                                     
                                蝙蝠岛资源网 Design By www.hbtsch.com
                            
                        
                        
                            
                                广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
                                免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
                                如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
                            
                        
                        
                        
                        蝙蝠岛资源网 Design By www.hbtsch.com
                        
                            
                                
                                    
                                    
                                    
                                        暂无PHP实现基本留言板功能原理与步骤详解的评论...
                                    
                                
                            
                        
                        
                    更新日志
2025年10月31日
                                2025年10月31日
                    - 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]
 
                        