留言板的主页

2018-06-04  本文已影响0人  sky枫

先来看下效果截图
输入用户名和密码后单击登录转跳到主页


201.PNG

这里就是一个简单的信息显示页面


203.PNG
下面看下源代码
<?php session_start(); ?>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">

<center>
    <title>留言</title>
</head>
<body background="6.jpg">
<?php
if (isset($_SESSION["uid"])){
    echo"欢迎你!". $_SESSION["username"];

    echo "<a href=\"percenter.php?uid='" . $_SESSION["uid"] . "'\">个人中心</a>";
            echo "<a href='denglu.php'>退出</a>";
    }else{
  die("无权访问,请登录后查看!<meta http-equiv='Refresh' content='0;url=denglu.php'/>");
}

?>

<h1>欢迎你!</h1>
<table border="0" cellpadding="30">
<tr>
<th>留言人</th>
<th>留言</th>
<th>ip</th>
<th>性别</th>
<th>时间</th>

</tr>
<?php
include "my.php";
$sql = "select * from message";
$result = mysqli_query($conn,$sql);
while ($message = mysqli_fetch_array($result) ) {

echo "<tr>";
    $sql1 = "select username,sex from user where uid ='".$message["uid"]."'";
    $result1 = mysqli_query($conn,$sql1);
    $persion = mysqli_fetch_array($result1);
    $user = $persion["username"];
    $sex = $persion["sex"];
    echo "<td>".$user."</td>";
    echo "<td>".$message["content"]."</td>";
    echo "<td>".$message["ip"]."</td>";
    echo "<td>".$sex."</td>";
    echo "<td>".$message["time"]."</td>";
    if($_SESSION["uid"]==$message["uid"]){
    echo "<td>  <a href='bianji.php?mid=" . $message["id"] . "'> 编辑</a></td>
            <td>    <a href=\"shanchu.php?mid=" . $message["id"] . "\">删除</a>
        </td>";
            }else{
                echo "<td >编辑</td>";
                echo "<td>删除</td>";

            }
    echo "</tr>";
    
}
?>

</table>
<form method="post" action="message.php">
<textarea name="content" rows="10" cols="80"></textarea>
<br />
<input type="submit" name="submit" value="添加留言">&nbsp;&nbsp;
<input type="reset" name="reset" value="重置">

</center>

</body>
</html>

这几行就是核心代码
限制了只能删除、编辑自己的留言和 输出了所有的留言信息
这里有几个sql和数据库交互的函数
mysqli_query() , mysqli_fetch_array() ,

<?php
include "my.php";
$sql = "select * from message";
$result = mysqli_query($conn,$sql);
while ($message = mysqli_fetch_array($result) ) {

echo "<tr>";
    $sql1 = "select username,sex from user where uid ='".$message["uid"]."'";
    $result1 = mysqli_query($conn,$sql1);
    $persion = mysqli_fetch_array($result1);
    $user = $persion["username"];
    $sex = $persion["sex"];
    echo "<td>".$user."</td>";
    echo "<td>".$message["content"]."</td>";
    echo "<td>".$message["ip"]."</td>";
    echo "<td>".$sex."</td>";
    echo "<td>".$message["time"]."</td>";
    if($_SESSION["uid"]==$message["uid"]){
    echo "<td>  <a href='bianji.php?mid=" . $message["id"] . "'> 编辑</a></td>
            <td>    <a href=\"shanchu.php?mid=" . $message["id"] . "\">删除</a>
        </td>";
            }else{
                echo "<td >编辑</td>";
                echo "<td>删除</td>";

            }
    echo "</tr>";
    
}
?>

这几行代码是添加留言的

<form method="post" action="message.php">
<textarea name="content" rows="10" cols="80"></textarea>
<br />
<input type="submit" name="submit" value="添加留言">&nbsp;&nbsp;
<input type="reset" name="reset" value="重置">

看效果截图


204.PNG 205.PNG
上一篇下一篇

猜你喜欢

热点阅读