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

php留言板代码

发布时间: 2023-05-24 12:20:30

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

已私信

热点内容
vb数据库程序 发布:2024-05-18 13:01:57 浏览:110
新建文件夹2免费手机 发布:2024-05-18 12:56:13 浏览:364
自己在家搭建服务器有水冷散热吗 发布:2024-05-18 12:47:27 浏览:648
旧版的安卓手机怎么使用微信 发布:2024-05-18 12:46:36 浏览:466
我的世界服务器开多久 发布:2024-05-18 12:45:32 浏览:592
vba获取网页表格数据库数据库数据库 发布:2024-05-18 12:23:24 浏览:699
腾讯服务器为什么卡顿 发布:2024-05-18 12:02:12 浏览:305
如何知道密码锁有没有nfc 发布:2024-05-18 11:58:09 浏览:961
单片机c语言模块化编程 发布:2024-05-18 11:53:16 浏览:644
win7xp共享打印机拒绝访问 发布:2024-05-18 11:51:00 浏览:847