概述
数据库部分!
index.php
<html>
<head>
<meta http-equiv="Content_Type" content="text/html; charset=gb2312">
<title>留言板</title></head>
</head>
<body>
<div align="right"><a href="admin_login.htm" targert="_blank"><font size="+1"
face="隶书">留言管理</font></a>
</div>
<div align="center"><font face="黑体"><h2>PHP学习交流留言板</h2></font>
</div>
<?php
$conn=mysql_connect("localhost","root","901120") or die("没有连接上服务器".mysql_error());
mysql_select_db("guest_book") or die("数据库连接不成功!".mysql_error());
mysql_query("SET NAMES GB2312");
echo "数据库连接成功<br>";
/*mysql_query("delete from contents")or die("删除表失败了!".mysql_error());
mysql_query("insert into contents(name,content) values("张三","php是什么东东"),
("李四","php很好学习吗?"),("狗五","php不好学呀,为啥?"),("王六","php还会流行多久")") or die("数据插入不成功!".mysql_error());
echo "插入成功了!<br>";
*/
$pageSize=3;
$pageNumber=$_GET[ 'pageNumber' ];
if($pageNumber==null)$pageNumber=1;
$rs=mysql_fetch_row(mysql_query("select count(*) from contents"));//取得记录个数
$totalCount=$rs[0];
$exec="select * from contents limit ".(($pageNumber-1)*$pageSize).",3";//sql语句
//(($pageNumber-1)*$pageSize).",3"中3是每一页中显示3个。
$result=mysql_query($exec);//执行sql语句,返回结果
while($rs=mysql_fetch_object($result)){ //利用循环语句输出结果
echo "<table><tr><td>姓名:".$rs->name."</td></tr>";//显示姓名
echo "<tr><td>留言:".$rs->content."</td></tr></table><br/>";//显示留言
echo "……………………………………………………………………………………………………………………………………";
echo "<br/>";
}
if($pageNumber>1){
echo "<a href=index.php?pageNumber=".($pageNumber-1).">前一页    </a>";
}
else{
echo "前一页    ";
}
if($pageNumber < $totalCount/$pageSize){//判断页数
echo "<a href=index.php?pageNumber=".($pageNumber+1).">后一页</a>";
}
else{
echo "后一页";}
mysql_close();
?>
<div align="CENTER"><a href="message_post.html" tagert="_blank">
<font size="+2" face="隶书"><p>我要留言</font></a>
</div>
</body>
</html>
<form action="updata.php" method="post" name="name1">
<table cellspacing=0 bordercolordark=#FFFFFF width="60%" bordercolorlight=#000000 border=1 align="center" cellpadding="2">
<tr bgcolor="#6b8ba8" style="color:FFFFFF">
<td width="100%" align="center" valign="bottom" height="19" colspan="2">访问者留言</td>
</tr>
<tr>
<td width="30%" align="center" height="30">留言人:</td>
<td width="70%" height="30"><input type="text" name="user" size="20" maxlength="21"></td>
</tr>
<tr>
<td height="80" align="center" width="30%" >留言内容:
</td>
<td height="80" width="70%">
<textarea name="post_contents" rows="10" cols="50"></textarea>
</td>
</tr>
<tr>
<td height="25" colspan="2" align="center">
<input type="reset" value="重置留言">
<input type="submit" value="提交留言">
</tr>
<table/>
</form>
留言处理
<?php
$name=$_POST['user'];
$content=$_POST['post_contents'];
$conn=mysql_connect("localhost","root","901120");
mysql_query("set names GB2312");
mysql_select_db("guest_book");
$exec="insert into contents(name,content) values ('".$_POST['user']."','".$_POST['post_contents']."')";
$result=mysql_query($exec)or die("添加留言不成功".mysql_error());
if($result>0)
echo "添加留言成功,谢谢您的留言!";
else
echo "<p><a href=index.php><center>返回主界面</center></a>";
mysql_close();
?>
<html><head><meta http-equiv='Refresh' content='3;URL=index.php'></head>
<body><p>谢谢您对本站的支持,三秒后将自动返……</p></body></html>
留言处理:
<?php
@session_start();
$admin_name=$_POST['admin_name'];
$admin_password=$_POST['admin_password'];
$conn=mysql_connect("localhost","root","901120") or die("服务器没有连接成功".mysql_error());
mysql_select_db("guest_book");
$exec="select * from admin where admin_name='".$admin_name."'";
$result=mysql_query($exec);
if($rc=mysql_fetch_object($result)){
if($rc->admin_password==$admin_password){
$_SESSION['admin']="ok";
header("location:admin_index.php");
}
else echo "密码不正确!";
}
else echo "用户名不正确!";
mysql_close();
?>
<html>
<head>
<title>后台管理界面</title>
</head>
<body>
<center><h1>后台管理界面</h1></center>
<?php
@session_start();
if($_SESSION['admin']=="ok"){
$conn=mysql_connect("localhost","root","901120");
mysql_query("set names GB2312");
mysql_select_db("guest_book");
$sexec="select * from contents";
$result=mysql_query($sexec) or die("没有选择出来结果".msql_err0r());;
while($rs=mysql_fetch_object($result)){
echo "<table><tr><tb>姓名:".$rs->name."</td><tr>";
echo "<table><tr><tb>留言:".$rs->content."</td><tr><br>";
echo "<a href=delete.php?id=".$rs->id.">删除</a>";
echo "<br><br>";
}
echo "<br><a href=index.php><center>回首页</center></a>";
}
mysql_close();
?>
</body>
</html>
<?php
@session_start();//以前犯错误了,在签名加一个@ 就不会提示错误了
if($_SESSION['admin']=="ok"){
$conn=mysql_connect("localhost","root","901120");
mysql_select_db("guest_book");
mysql_query("set names GB2312");
$exec="delete from contents where id=".$_GET['id'];
mysql_query($exec) or die("没有删除成功 !".mysql_error());
//echo "删除成功了!";
mysql_close();
}
header("location:admin_index.php");
?>
最后
以上就是明亮金鱼为你收集整理的留言板php代码。的全部内容,希望文章能够帮你解决留言板php代码。所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复