當前位置:首頁 » 編程語言 » 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

這樣就可以實現無限回復了!

熱點內容
安卓手機怎麼轉移蘋果系統 發布:2024-09-17 04:19:07 瀏覽:934
sql從表中查詢數據 發布:2024-09-17 04:19:07 瀏覽:972
米粒泥解壓 發布:2024-09-17 04:19:01 瀏覽:729
2010word加密方法 發布:2024-09-17 04:17:36 瀏覽:282
crv哪個配置性價比高2021 發布:2024-09-17 04:07:51 瀏覽:36
wincc圖形編譯在哪裡 發布:2024-09-17 03:58:26 瀏覽:978
androidubuntu 發布:2024-09-17 03:50:27 瀏覽:702
識夢源碼 發布:2024-09-17 03:50:18 瀏覽:27
諾基亞密碼忘了打什麼電話 發布:2024-09-17 03:27:09 瀏覽:556
樹深度優先演算法 發布:2024-09-17 03:26:58 瀏覽:474