php留言板代碼
① php留言板 代碼出錯
養成良好的編程習慣,把下面旁山這一段:
if(mysql_query($sql,$link))
echo "留言成功";
else
echo "留言失敗";
修改為:
if(mysql_query($sql,$link))
echo "留言成功";
else
echo "留言失敗,SQL:$sql<br>錯誤:".mysql_error();
這樣,發現問槐啟侍題的時候你自己就能解決,鉛吵根本不用發帖子,不信你試試看。
② 用PHP寫留言板代碼時怎樣才能實現刪除和修改留言的啊代碼是怎樣的
list.php修改下
在你顯示每個樓層的留言信息後面加上一行
<a href="del.php?id=<?php echo $row['id']; ?>">刪除</a>
<a href="update.php?id=<?php echo $row['id']; ?>">編輯</a>
然後建立del.php文件
<?php
if (isset($_GET['id']))
{
include_once(你建立mysql連接的那個php文件);
mysql_query('DELETE FROM `bbtliuyanban` WHERE `id` = \'' . $_GET['id'] . '\'');
}
?>
就一句話,mysql_query執行刪除語句就好了
重點是GET接收到傳遞來的ID值
建立update.php
<?php
include_once(你建立mysql連接的那個php文件);
if (!empty($_POST))
{
mysql_query("UPDATE `bbtliuyanban` SET `user` = '$_POST[user]', `title` = '$_POST[title]', `content` = '$_POST[content]' WHERE `id` = '$_POST[id]'");
}
if (isset($_GET['id']))
{
$result = mysql_query('SELECT * FROM `bbtliuyanban` WHERE `id` = \'' . $_GET['id'] . '\'');
$row = mysql_fetch_array($result);
?>
輸出標單信息
<form action="update.php" method="POST">
<input type="hidden" name="id" value="<?php echo $row['id']; ?>" />
標題:<input type="text" name="title" value="<?php echo $row['title']; ?>" />
用戶:<input type="text" name="user" value="<?php echo $row['user']; ?>" />
<textarea name="content"><?php echo $row['content']; ?></textarea>
<input type="submit" />
</form>
<?php
}
?>
臨時開下電腦,趕時間,有疑問明天再說吧
update沒少大括弧吧?
最後有的,你是不是沒注意到?
輸出表單信息這行可以刪了,你就完整復制從建立update.php下面到臨時開下電腦之間所有代碼就行了,小毛病自己改改,直接在這里打的沒太注意細節
許可權要用到cookie和sessions
你才學3天。。。貪多嚼不爛
樓下說的挺對,但是有一點,有管理員許可權才能進行刪除、修改操作
所以對del的判斷基本上沒必要
防sql還是要的,謝謝提醒了
③ php留言板項目怎麼做
本項目需要鋒鍵數phpmysql來實現。
首先需要分析資料庫:
需要建立用戶表(user)
表中欄位:編號(id int primary key auto_increment),昵稱(nickname varchar(255)),性別(sex int(1) 男為1,女為0),郵箱(email varchar(255)),注冊時間(reg_time varchar(255) 時間戳)
還需要建立留言表(leaveword)
表中欄位:編號(id int primary key auto_increment),留言用戶編號(user_id int),留言內容(content text),留言時間(leaveword_time varchar(255))
建完表並插入一些測試數據後,就開始設計頁亮跡面了。
當用戶登錄後,需要把用戶的id存入session中$_SESSION['user_id'],以便用來驗證用戶是否登錄,是否有許可權發表留言。
用戶進入到留言頁面中以後,需要分頁展示其他(包括自銀首己)的留言。
④ 用PHP怎麼做留言板
我來教你:
首先你要建立一個mysql資料庫
然後在資料庫裡面設置欄位 例如 用戶 留言
當你在html頁面的文本框填寫留言後,用表單點擊提交(在表單裡面要設置提交到那個頁面 比如:index.php)
當你提交到改頁面後,在這個頁面填寫你的php代碼
就是連接資料庫,然後將你的留言寫進資料庫
最後查看 和刪除 就是執行資料庫常見的查詢功能和刪除功能了
⑤ 求一步一步教PHP留言板製作方法
1. 先設計數據表,一般留言板需要兩個表:留言內容表、回復表
留言內容表:messages
欄位如下:
id 自動增加
contents 留言內容
messages_time 留言時間
回復表:reply
欄位如下:
id 自動增加
messages_id 關聯messages表的id
contents 回冊螞復的內容
reply_time 回復時間
2. 設計留言板頁面及保存留言數據
大概代碼如下:州灶埋
<form name="form1" method="post" action="index.php?action=ok">
<texarea cols="30" rows="10" name="contents">
</textarea>
<input type="submit" value="提交">
</form>
<?php
if($_GET['action'] == 'ok'){
$contents = $_POST['contents'];
mysql_query("insert into messages values(NULL,'".$contents."',now())");
}
?>
3. 顯示留言內容,遍辯胡歷數據表
<?php
//包含數據連接代碼
require('data.php');
$query = mysql_query("select * messages");
while($array = mysql_fetch_array($query)){
echo $array['contents']."<br>";
}
?>
4. 回復的設計可以參照留言的設計
⑥ 誰能提供一個PHP留言板源碼
我自己有一個簡單的留言板系統,
裡面有簡單的增刪改查功能,需要會資料庫。
希望可以幫助到有緣的學習愛好者。
這是首頁index.php代碼:
<html>
<head>
<title>我的留言本</title>
<script type ="text/javascript">
function dodel(id){
if(confirm("確定要刪除嗎?")){
window.location="action.php?action=del&id="+id;
}
}
</script>
<style type = "text/css">
*{font-family:"微軟雅黑";}
body{
background:url(images/bg.gif);
}
a{color:#000;text-decoration:none;}
a:hover{text-decoration:underline;}
td{text-align:center;}
table{
border:3px solid #9b9b9b;
background:#E9E9E9;
}
td{
color:#660000;
}
</style>
</head>
<body>
<center>
<?php include("menu.php"); ?>
<h3>瀏覽新聞</h3>
<table width ="880" border="1" cellpadding="3">
<tr>
<th>新聞id</th><th>新聞標題</th><th>關鍵字</th><th>作者</th><th>發布時間</th><th>新聞內容</th><th>操作</th>
</tr>
<?php
//1.導入配置文件
require("dbconfig.php");
//2.鏈接mysql資料庫,選擇資料庫
$link = @mysql_connect(HOST,USER,PASS)or die("資料庫連接失敗!");
mysql_select_db(DBNAME,$link);
//3.執行查詢,並返回結果
$sql="select * from news order by addtime desc";
$result = mysql_query($sql,$link);
//4.解析結果集,並遍歷輸出
while($row = mysql_fetch_assoc($result)){
echo"<tr>";
echo"<td>{$row['id']}</td>";
echo"<td>{$row['title']}</td>";
echo"<td>{$row['keywords']}</td>";
echo"<td>{$row['author']}</td>";
echo"<td>{$row['addtime']}</td>";
echo"<td>{$row['content']}</td>";
echo"<td>
<a href='javascript:dodel({$row['id']})'>刪除</a>
<a href='edit.php?id={$row['id']}'>修改</a></td>";
echo"</tr>";
}
//5.釋放結果集
mysql_free_result($result);
mysql_close($link);
?>
</table>
</center>
</body>
</html>
⑦ PHP留言板系統代碼問題 資料庫和表都建了 為什麼在頁面就是提交不上去請教高手什麼原因
php區分大扒裂小寫:
$_post在php中不存在(除非春碧閉自己自定義數組)
$_POST才是正慧嘩確的
⑧ 求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做出登陸注冊留言板
用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完成留言板功能
留言表:留言ID、用戶ID、內容、發表時間、修改時間(此欄位可選)。
回復表:回復ID、留言ID、用戶ID、內容、發表時間、修改時間(此欄位可選)。
第一個用戶ID是誰發表的留言,第二個用戶ID是誰回復的留言,這樣無限回復沒問題,應該和你設計的差不多。
查詢(查詢某條留言的所有回復):
在回復表裡查詢所有該留言的回復記錄(查詢條件為留言ID),並按發表時間降序
回復內容表:
回復Id 回復內容
回復關聯表:
回復內容id 回復內容id
已私信