Ⅰ 关于php简易留言板的一小段代码..
我先给每行程序加上注释
<?php
$name=$_POST['name'];//获取表单提交过来的数据
$note=$_POST['note'];//同上
$db=new mysqli('localhost','root','123','dlw');//连接mysql数据库并选择dlw数据库,很老的写法了,不建议这么使用。
$sql="insert into gustbook values(name,time,words)";//sql语句
$sql=$sql.$name;//等同于sql .= $name 相当于让上面那条sql语句后面连接$name但是这里在$name前面漏掉了一个( 应该是$sql = $sql."(".$name
$sql=$sql."',now(),'".$note."')";//同上
$result=$db->query($sql);//执行sql语句
echo"<center>write successfully.</center><br><br>";//输出write successfully字符串,没有任何意义,因为不管执行成不成功他都输出。
?>
<html>
<body bgcolor="FFCCCC">
<center>
<a href="do.php">write again</a><br><br>
<a href="index.php">check out the message</a>
</center>
</body>
</html>
这应该是个很老的程序,你要用首先要改正几个地方的写法
1、$db=new mysqli('localhost','root','123','dlw');
最好写成
mysql_connect('localhost','root','123');
mysql_slect_db('dlw');
2、 $sql="insert into gustbook values(name,time,words)";
$sql=$sql.$name;
$sql=$sql."',now(),'".$note."')";
可以写一个sql语句就可以了,不用去连接,而且最好用标准的写法。
$sql = "insert into gustbook (name,time,words) values ('".$name."',now(),'".$note."')";
3.$result=$db->query($sql);
echo"<center>write successfully.</center><br><br>";
加一个写入成功的判断
if(mysql_query($sql)){//注意这里不是$db因为我们前面把mysqli这个类已经省掉了。
echo"<center>write successfully.</center><br><br>";
}else{
"<center>write false.</center><br><br>";
}
具体留言不成功,可能还有几个问题,首先你的数据库有没有这几个字段,还有具体有没有连接成功数据库,你可以用phpmyadmin看一看你的留言内容是不是已经写入数据库,如果有但没显示,那应该是读取时候的问题,就不是你这个程序的问题了。
你用我给说的写法试一下也不行吗。
mysql_slect_db('dlw');
你确定数据库连接成功了吗,
把mysql_connect('localhost','root','123');改为
mysql_connect('localhost','root','123') or die("数据库连接不成功");
如果数据没有进去,那就跟index.php没有任何关系,我看一下你现在的这个程序。表单还有添加的程序,还有数据表的结构。
Ⅱ php留言板审核功能怎么做
第一步:把留言板的列表数据列出来(按留言倒序查询),正常的呈现都是表格的方式。
第二部:每行留言都有审核通过,审核不通过的按钮。正常选择不通过需要填写原因。
如图所示
Ⅲ php留言板
我给你一个我自己做的留言板的代码吧,你只需创建数据库,把代码复制过去即可使用。如下:
创建数据库:
create database stud;
use stud;
create table student(username char(20) not null,message char(200) not null);
PHP代码:
文件index.html
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>留言板</title>
</head>
<body>
<SCRIPT LANGUAGE="javascript">
<!--
function openwin(){
window.open ('message.html', '添加留言', 'height=400, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
return flase;
}
-->
</SCRIPT>
<a href="#" onclick="openwin()">我要留言</a>
<a href="show.php">查看留言</a>
</body>
</html>
文件message.html
<title>留言板</title>
</head>
<body>
<form id="form1" name="form1" method="POST" action="post.php">
<label>姓名
<input type="text" name="username" />
</label>
<p>
<label>留言
<textarea rows="5" name="message" ></textarea>
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="提交" />
</label>
<label>
<input type="reset" name="Submit2" value="重置" />
</label>
</p>
</form>
</body>
</html>
文件post.php
<?php
$link=mysql_connect('localhost','root','123456');
mysql_select_db('stud',$link);
mysql_query("set names 'gb2312' ");
if($_POST['Submit'])
$query="INSERT INTO student(username,message)VALUES('$_POST[username]','$_POST[message]')";
if(mysql_query($query))
{echo"提交成功";
header("location:index.html");}
else
{echo"提交不成功";}
?>
文件show.php
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>结果</title>
</head>
<body>
<?php
$link=mysql_connect('localhost','root','123456');
mysql_select_db('stud',$link);
mysql_query("set names 'gb2312' ");
$result=mysql_query("select*from student",$link);
$count=mysql_num_rows($result);
$all=$count-1;
?>
<table width="418" border="1" align="center">
<tr align="center">
<td width="130"> <?php echo"用户名" ?> </td>
<td width="280"> <?php echo"留言内容" ?> </td>
</tr>
<?php
while($row=mysql_fetch_array($result))
{
?>
<tr align="center">
<td width="130"> <?php echo$row[username] ?> </td>
<td width="280"> <?php echo$row[message] ?> </td>
</tr>
<?php
}
?>
</table>
一共有<?php echo$all+1; ?>条留言<a href="index.html">返回首页</a>
</body>
</html>
代码完毕!!
Ⅳ 如何用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制作留言板代码
<form action="留言方法,也可以是留言.php文件,也可以是当前页面" method="get">
<p>First name: <input type="text" name="fname" /></p>
<p>Last name: <input type="text" name="lname" /></p>
<input type="submit" value="Submit" />
</form>
php:
$fname=$_GET[fname];
$lname=$_GET[lname];
$sql = "insert into 表名(字段1,字段2) values('$fname','$lname')";
if(!$sql ){
return "插入失败";
}else{
return "成功添加数据";
}
Ⅵ 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'],以便用来验证用户是否登录,是否有权限发表留言。
用户进入到留言页面中以后,需要分页展示其他(包括自银首己)的留言。