当前位置:首页 » 编程语言 » php留言板

php留言板

发布时间: 2022-01-12 03:24:39

php留言板的回复怎么做

首先得设计好数据库,留言一个表,回复一个表,然后把留言表中关键字ID关联到回复表中。
比如:
留言表:message
id
contents
user
time
回复表:reply
id
m_id 关联留言表中的id
contents
user
time

然后程序方面把对应的留言、回复保存到相应的表中,读取的时候先遍历留言表,然后通过留言表id再读取对应的回复数据。

② 如何用php做出登陆注册留言板

用php做出登陆注册留言板:

<form id="form1" name="form1" method="post" action="<?php echo site_url()."/publish/user_message"?>">
<textarea rows="5" cols="50" name="huifu" <?php if($uere_name == "0"){echo "disabled";}?> >
<?php
if($uere_name == "0")
{echo "抱歉你还没登录不能进行留言";}
?>
</textarea>
<input class="wole" name="author" value="<?php echo $author;?>" /><!--接受方帖子作者-->
<input class="wole" name="news_id" value="<?php echo $news_idx;?>" /><!--文章id-->
<input type="submit" name="Submit"/>
</form>
<script language="javascript">
function updateinfo(){
if(<?php echo $uere_name;?> == 1){
document.form1.Submit.value = "留言";
document.form1.Submit.disabled = false;
}
else{
document.form1.Submit.value = "还未登录";
document.form1.Submit.disabled = "disabled";
}
}
updateinfo();
</script>

回复帖子:

<p>这里是<?php echo $is;?>楼 用户:<?php echo $sel->receiver_author;?> <br />留言内容:<?php echo $sel->content?>


<a onClick="showdiv('contentid<?php echo $is;?>','showtext<?php echo $is;?>')" href="javascript:void(0)">回复</a>
<div id="contentid<?php echo $is;?>" class="none">
<?php
$query = $this->db->query("select * from message where son_id ='$sel->id' order by id");//获取指定父id的子回复
$revis = $query->result();
foreach($revis as $row){?>
<p><?php if($row->sender_author == $row->receiver_author){echo $row->sender_author;}
else{ echo $row->sender_author."回复了:".$row->receiver_author;}?>
内容是:<?php echo $row->content?></p>
<?php }?>
<form action="<?php echo site_url()."/publish/son_message"?>" method="post">
<input name="son_idx" class="wole" value="<?php echo $sel->id?>" />
<input name="receiver_author" class="wole" value="<?php echo $sel->receiver_author;?>" />
<input class="wole" name="news_id" value="<?php echo $news_idx;?>" /><!--文章id-->
<textarea rows="5" cols="50" name="huifux"></textarea>
<br><input type="submit" name="sub" value="回复"></form></div></p>
<script language="JavaScript" type="text/JavaScript">
<!--
function showdiv(targetid,objN){

var target=document.getElementById(targetid);
var clicktext=document.getElementById(objN)

if (target.style.display=="block"){
target.style.display="none";
clicktext.innerText="回复";

} else {
target.style.display="block";
clicktext.innerText='收起';
}
}
-->
</script>

效果图:

③ 求php语言编写的留言板源码!!!!!!!!!

这是一个简单的留言本,目前还没有后台管理程序。如果哪位高手能补上,那就太好了。

演示在http://www.ideawu.net/person/liuyan

留言保存在message.txt文件中,留言的格式为:date<$>ip<$>name<$>content
"<$>"为分隔符号

注意:源码文件和message.txt文件必须以gbk格式保存。如果你不知道如何保存文件为gbk格式,请咨询你的文本编辑器软件提供商。

/****************************************
* 本代码可以用作任何用途,但是与作者无关。
* 也就是,你使用本代码获取收益或者因此受
* 到损害,后果与作者无关。
****************************************/

file: index.php
代码:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>留言板</title>
<link rel="stylesheet" href="../msg.css" type="text/css">
</head>
<body>
<br><B><FONT COLOR="#0000FF">图片留言板</FONT></B>
<center>
<table width="800" border="1" bordercolor="#88CCEE" cellspacing="0" cellpadding="4" style="border-collapse:collapse; word-break:break-all">
<tr><td style="border-right-style: none">
<form method="post" action="savemsg.php" style="font-size: 13px">
姓名:<br><input type="text" name="guest_name" maxlength=32 size=32><br>
留言:(字数:<font color="#0000FF"><span id=sNum>0</span></font>/256)<br>
<textarea class="textForm" name="guest_msg" cols="64" rows="8" onkeyup="sNum.innerHTML=this.value.length"></textarea><br>
<input class="button" type="submit" name="submit" value="发表留言">
<input class="button" type="reset" value="重置" name="reset">
</form>
</td></tr>
</table>
<?php
include("showmsg.php");
if(!empty($_GET['p'])){
$num=$_GET['p'];
showpage($num);
}else showpage(1);
?>
</center>
</body>
</html>

file: showmsg.php
代码:

<?php
function showpage($p)
{ ?>
<table width="800" border="0" bordercolor="#88CCEE" cellspacing="0" cellpadding="4" style="border-collapse:collapse; word-break:break-all;font-size:12px;">
<tr><td>
<p style="line-height: 100%; margin-top: 1; margin-bottom: 1" align="left">
<?php
$perPage=7; //每页显示留言数目
$num=$p;
if($num<1) $num=1;
$prev=$num-1;
$next=$num+1;
$page=$num-1; //当前页码
$fname="message.txt"; //存储留言的文件
$all_msg=file($fname); //将留言读入数组
$line_count=count($all_msg);
$page_count=ceil($line_count/$perPage);
if($prev>0)
echo "<a href=index.php?p=$prev>上一页</a>";
else
echo "上一页";
if($line_count>($next-1)*$perPage)
echo "<a href=index.php?p=$next>下一页</a>";
else
echo "下一页";
echo "当前第 ".$num." 页,共有".$page_count."页,".$line_count."条留言。";
?>
</p></td></tr>
</table>
<table width="800" border="1" bordercolor="#88CCEE" cellpadding="3" cellspacing="0" style="border-collapse:collapse; font-size:12px; word-break:normal; table-layout:fixed;">
<tr height="18" bgcolor="#5FBEF8"><td width="20%">
<b>留言时间/留言者</b></td><td width="86%"><b>留言内容</b>
</td></tr>
<?php
//显示留言
$bg1="#FBF9F9"; $bg2="#E9EFF4";$bg=$bg2;
for($n=$line_count-1-$page*$perPage;$line_count-1-$page*$perPage-$n<$perPage;$n--){
$bg=($bg==$bg1)? $bg2:$bg1; //变换背景颜色
if(!empty($all_msg[$n])){
list($date,$ip,$name,$msg)=explode("<$>",$all_msg[$n],4); //获取留言内容
echo "<tr bgcolor=$bg>";
echo "<td width=14%>".$date."<br><b>".$name."</b></td>";
echo "<td width=86%>".$msg."</td>";
echo "</tr>";
}
}
?>

</table>
<table width="800" border="0" bordercolor="#88CCEE" cellspacing="0" cellpadding="4" style="border-collapse:collapse; word-break:break-all;font-size:12px">
<tr><td>
<p style="line-height: 100%; margin-top: 2; margin-bottom: 2" align="left">
<?php
if($prev>0)
echo "<a href=index.php?p=$prev>上一页</a>";
else
echo "上一页";
if($line_count>($next-1)*$perPage)
echo "<a href=index.php?p=$next>下一页</a>";
else
echo "下一页";
echo "当前第 ".$num." 页,共有".$page_count."页,".$line_count."条留言。";
?>
</p></td></tr>
</table>
<?php } ?>

file: savemsg.php
代码:

<?php
$MSG_MAX_LEN=512; //留言最大长度
if (getenv("HTTP_CLIENT_IP"))
$ip= getenv("HTTP_CLIENT_IP");
elseif (getenv("HTTP_X_FORWARDED_FOR"))
$ip= getenv("HTTP_X_FORWARDED_FOR");
else
$ip= getenv("REMOTE_ADDR");
//获取IP地址结束
$date=date("Y年m月d日 H:i:s",time());
if(empty($_POST['guest_name']))
die("请填你的名字。<a href=index.php>Refresh</a>");
if(empty($_POST['guest_msg']))
die("请填写留言内容再提交。<a href=index.php>Refresh</a>");
$guest_name=strip_tags($_POST['guest_name']);
$guest_msg=substr($_POST['guest_msg'],0,$MSG_MAX_LEN);
//write message to file
//make the message be a line when stored
$guest_msg = str_replace( "\r\n", "\n", $guest_msg);
$guest_msg = str_replace( "\r", "\n", $guest_msg);
$guest_msg = str_replace(" "," ",$guest_msg);
$guest_msg = str_replace(">",">",$guest_msg);
$guest_msg = str_replace("<","<",$guest_msg);
$guest_msg = str_replace("\'","'",$guest_msg);
$guest_msg = nl2br($guest_msg);
//保存留言,以追加的形式
$fname="message.txt";
$fp=fopen($fname,"a+");
fwrite($fp,$date."<$>".$ip."<$>".$guest_name."<$>".$guest_msg."\n");
fclose($fp);
echo "<meta http-equiv='refresh' content='0;url=index.php'>";
?>

用于显示效果的样式表文件
file: msg.css
代码:

A:link {
color: #0033FF;
text-decoration: none;
}

A:visited {
color: #0033FF;
text-decoration: none;
}

A:hover {
color: #30A300;
text-decoration: underline;
}

A:active {
color: #0036A9;
text-decoration: none;
}

BODY{
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size: 12px;
background: #FBF9F9;
}

TABLE{
font-family: Verdana,Arial,Helvetica,sans-serif;
font-size: 12px;
border-collapse: collapse;
table-layout: fixed;
margin: 0px;
}

④ PHP 留言板编辑器

你直接用开源的编辑器就可以!我推荐KindEditor,挺方便的.
http://kindeditor.net/docs/usage.html这个是使用方法!

⑤ php+mysql留言板的源代码

有视频,你可以跟着做。要加什么功能还可以自己发挥。。。

⑥ php留言板中怎么删除

首先在留言详情的后面添加一个标签

<a href="/localhost/message/delete?id=<?=$item->id?>">删除</a>

就是点击到这个删除,就会传递一个留言的id值到相应的页面

然后在该页面执行数据库操作 delete ( 'tablename' ,'id'=$id);

写SQL语句就行了

publicfunctiondelete()
{
//我这写的是MVC模式下的
$id=$this->input->get('id',TRUE);//get方法获取链接后的id值
$this->db->where('id',$id);
$this->db->delete('list');
//

}

⑦ 想写个PHP留言板,请问要怎么做

1. 先设计数据表,一般留言板需要两个表:留言内容表、回复表
留言内容表:messages
字段如下:
id 自动增加
contents 留言内容
messages_time 留言时间
回复表:reply
字段如下:
id 自动增加
messages_id 关联messages表的id
contents 回复的内容
reply_time 回复时间
2. 设计留言板页面及保存留言数据
大概代码如下:
3. 显示留言内容,遍历数据表
4. 回复的设计可以参照留言的设计

⑧ php建立留言板问题

Notice是提示级别,不算出错,不影响程序正常运行,你可以在php.ini文件中配置error_reporting项将其关闭,也可以在代码中加入
@error_reporting(E_ALL & ~E_NOTICE);来屏蔽。

Undefined variable指的是变量未声明。有php中变量是不用声明就可以直接使用的,所以只是Notice,而不是Error或者warning
想用更规范的编程风格就先声明变量吧。

这里$_POST是客户端传来,不便事先申明,规范的写法是先判断变量是否存在再引用,就不会有这个提示了,常见的写法如下:
$user=isset($_POST['user'])?$_POST['user']:'';

当然,这里还应该做更多的判断,对变量进行过滤。
你这样直接传入SQL有严重的安全隐患。

⑨ php 留言板 留言和回复

看了你的问题.和数据库的2个表设计.
1.先确定数据表的设计.
留言表 message
字段:
msgid
uid
content
postdate

回复表replies
repliesid
uid
msgid
content
postdate

这样的设计表,我认为是最好的。符合数据库的范式,主要是简单明了,简单就意味着性能.

2.怎么把数据库合理的提取出来,只能说是从代码上着手.
第一种最直接的方法。
$sql = "select * FROM message order postdate desc";
得到$messages留言的数组
foreach ($message as $key => $value) {
$sql = "select * from replies where msgid = ".$value['msgid'];
得到留言对应的回复$replies
$message[$key]['replies'] = $replies;
}
最终得到数组$message;
前台显示:
foreach( $messsage as $key => $value ) {
echo $value[‘content']; //显示留言
foreach( $value['replies'] as $k => $val ) {
echo $val['content'];//显示该留言下的恢复
}
}

第二中方法,我比较喜欢,而且也一直在用
$sql = "select * FROM message order postdate desc";
得到$messages;
通过处理得到,数组$messages中的所有msgid,并存入一维数$msgids
$msgids = array();
$result = array(); //这个数组转化$messages用的.因为我们要把$messages的key值变成msgid
foreach( $message as $key => $value ) {
$msgids[] = $value['msgid'];
$result[$value['msgid']] = $value;
}
unset($messages); 这个数据就没有用了。因为已经有$result;

一次性查询出,这些留言需要的所有回复,$replies;
$sql = "select * from replies WHERE msgid in (".implode(',',$msgids).") order by postdate desc";
foreach( $replies as $key => $value ){
$result[$value['msgid']]['replies'][] = $value;
}

前台显示:
foreach( $resultas $key => $value ) {
echo $value[‘content']; //显示留言
foreach( $value['replies'] as $k => $val ) {
echo $val['content'];//显示该留言下的恢复
}
}

⑩ php留言板是实现无限回复功能

个人觉得建立一个专门的数据库表就可以了,给每个回复一个id然后在每次有回复后将这个id对应的回复写入表中就ok了!
回复内容表:
回复Id 回复内容

回复关联表:
回复内容id 回复内容id

这样就可以实现无限回复了!

热点内容
pythonshutdown 发布:2024-09-19 10:04:07 浏览:561
ftp连接工具安装 发布:2024-09-19 09:56:57 浏览:192
nba2kol2安卓手游怎么下 发布:2024-09-19 09:55:28 浏览:11
服务器换位置了ip地址怎么换 发布:2024-09-19 09:33:50 浏览:798
javarest 发布:2024-09-19 09:28:43 浏览:753
密码子的原料是什么 发布:2024-09-19 09:11:42 浏览:348
半夜编程 发布:2024-09-19 09:11:36 浏览:104
海康威视存储卡质量如何 发布:2024-09-19 08:55:35 浏览:941
python3默认安装路径 发布:2024-09-19 08:50:22 浏览:517
环卫视频拍摄脚本 发布:2024-09-19 08:35:44 浏览:419