前言:想了 一下还是把留言的东西发一下吧.
一、留言
<?php
session_start();
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>留言板系统</title>
<style>
.main{width: 80%;margin: 0 auto;text-align: center;}
h2{font-size: 20px}
h2 a{color: navy;text-decoration: none;margin-right: 15px}
h2 a:last-child{margin-right: 0}
h2 a:hover{color: brown;text-decoration: underline}
.current{color: brown}
.red{color: red}
.message
{
width:600px;
height:170px;
background:#fff;
background:rgba(255,255,255,0.25);
margin: 100px auto 0;
border: radious 5px;
padding: 5px;
}
.message p
{
color:black;
font-size:12px;
line-height:25px;
}
.message .text
{
width: 600px;
height:70px;
border: 1px solid #ddd;
background:rgba(255,255,255,0.25);
}
.message .btn
{
width:600px;
height: 100px;
margin-top:10;/* 遇上个边框的距离为10像素 */
}
.message .btn .face-btn
{
float:left;
}
.message .btn .mes-btn
{
float:right;
background:rgba(255,255,255,0.25);
padding: 0px 5px;
border-radius:0px;
font-size:12px;
cursor:pointer;/* 设置鼠标形状。 */
}
.message .btn input
{
float:right;
background:rgba(255,255,255,0.25);
padding: 5px 20px;
border-radius:5px;
font-size:12px;
cursor:pointer;/* 设置鼠标形状。 */
}
</style>
</head>
<body background="A.jpg"
style="background-repeat:no-repeat;
background-attachment: fixed;
background-size: 100% 100%;">
<div class="main">
<h1>留言板系统</h1>
<?php
if(isset($_SESSION['loggedUsername']) && $_SESSION['loggedUsername'] <> ''){
?>
<div class="logged">当前登录者:<?php echo $_SESSION['loggedUsername'];?> <?php if($_SESSION['isAdmin']) {?><span style="color: crimson">欢迎管理员登录</span><?php }?> <span class="logout"><span class="logout"><a href="logout.php">注销登录</a></span> </div>
<?php
}
?>
<h2>
<a href="留言.php">发表留言</a>
<a href="查看留言.php">查看留言</a>
<a href="修改.php"> 修改密码</a>
<a href="admin.php"> 后台管理 </a>
</h2>
</div>
<form action="留言后端.php" method="post">
<div class="message" style="background-color:palegoldenrod">
<div class="btn">
<p align="center" style="font-size: 30px;" > 请在下面发表留言 </p>
<textarea name="text" cols="50" rows="10" class="text"></textarea>
<span><p align="right"><input type="submit" value="发表留言" ></p></span>
</div>
</div>
</form>
</div>
<?php
session_start();
$text = $_POST['text'];
$username= $_SESSION['loggedUsername'];
$date=date("Y-m-d H:i:s",time());
include_once "conn.php";
//sql语句
$sql = "insert into speak (username,text,time) values ('$username','$text','$date')";
$result = mysqli_query($conn,$sql);
if($result){
echo "<script>alert('发表成功');location.href='查看留言.php'</script>";
}
else{
echo "<script>alert('发表失败');history.back();</script>";
}
二、查看留言
<?php
session_start();
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>留言板系统</title>
<style>
.main {
width: 80%;
margin: 0 auto;
text-align: center;
}
h2 {
font-size: 20px
}
h2 a {
color: navy;
text-decoration: none;
margin-right: 15px
}
h2 a:last-child {
margin-right: 0
}
h2 a:hover {
color:burlywood;
text-decoration: underline}
tr:hover{background-color: azure}
.trClick1{background-color:purple }
.trClick2{background-color:palegreen
}
</style>
</head>
<body background="E.jpg"
style="background-repeat:no-repeat;
background-attachment: fixed;
background-size: 100% 100%;">
<div class="main">
<h1>留言板系统</h1>
<?php
if(isset($_SESSION['loggedUsername']) && $_SESSION['loggedUsername'] <> ''){
?>
<div class="logged">当前登录者:<?php echo $_SESSION['loggedUsername'];?> <?php if($_SESSION['isAdmin']) {?><span style="color: crimson">欢迎管理员登录</span><?php }?> <span class="logout"><span class="logout"><a href="logout.php">注销登录</a></span> </div>
<?php
}
?>
<h2>
<a href="留言.php">发表留言</a>
<a href="查看留言.php">查看留言</a>
<a href="修改.php"> 修改密码</a>
<a href="admin.php"> 后台管理 </a>
</h2>
<?php
//连接留言数据库
include_once 'conn.php';
$sql = "select * from speak order by id desc ";
$result = mysqli_query($conn, $sql);
//接用户数据库
$myd = "select * from info order by id asc ";
$return =mysqli_query($conn,$myd);
$name =$_SESSION['loggedUsername']
?>
<table border="1" cellspacing="0" cellpadding="10" style="border-collapse: collapse" align="center" width="90%">
<tr style="background-color: burlywood;">
<td>用户名</td>
<td>内容</td>
<td>时间</td>
<td>操作</td>
</tr>
<?php
while ($speak = mysqli_fetch_array($result))
{
$s=$speak['id'];
?>
<tr onclick="if(this.className == 'trClick2'){this.className = 'trClick1'}
else{this.className = 'trClick2'}" class="trClick2"
style="background-color: burlywood;">
<td><?php echo $speak['username']; ?></td>
<td><?php echo $speak['text'];?> </td>
<td><?php echo $speak['time'];?> </td>
<td><font>
<?php
if($_SESSION['isAdmin']) { ?>
<a href="delete.php? id=<?php echo $s; ?>">[删除]</a>
<a href="change.php? id=<?php echo $s; ?>">[修改]</a>
<?php }
else{
if($speak['username'] <> $name) { ?>
<span style='color:gray'>[删除]</span>
<span style='color:gray'>[修改]</span>
<?php }
else{ ?>
<a href="delete.php? id=<?php echo $s; ?>">[删除]</a>
<a href="change.php? id=<?php echo $s; ?>">[修改]</a>
<?php
}
}?>
</font>
</td>
</tr>
<?php
}
?>
</table>
</div>
</body>
</html>