温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

php怎样实现留言板功能

发布时间:2021-06-20 17:28:08 来源:亿速云 阅读:225 作者:小新 栏目:开发技术

这篇文章将为大家详细讲解有关php怎样实现留言板功能,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

具体内容如下

数据库用到的三张表

php怎样实现留言板功能

php怎样实现留言板功能

php怎样实现留言板功能

一.登录界面 (denglu.php   login.php)

php怎样实现留言板功能

1.denglu.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>

<body>
<h2>开发部内部留言板</h2>
<form action="login.php" method="post">
<div>用户名:<input type="text" name="UserName" /></div>
<div>口令:<input type="password" name="PassWord" /></div>
<input type="submit" value="登录" />
<a href="denglu.php" ><input type="button" value="复位" /></a>
</form>
</body>
</html>

2.login.php

<?php
session_start();
$UserName = $_POST["UserName"];
$PassWord = $_POST["PassWord"];

require "DBDA.class1.php";
$db = new DBDA();
$sql = "select PassWord from yuangong where UserName = '{$UserName}'";
$arr = $db->query($sql);

if(count($arr))
{
  if($arr[0][0] == $PassWord && !empty($PassWord))
  {
    //存储用户名
    $_SESSION["UserName"] = $UserName;
    
    header("location:main.php");
  }
}
else
{
  header("location:denglu.php");
}

二.主界面(main.php   tuichu.php)

php怎样实现留言板功能

1.main.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<?php
session_start();
  
//  防止绕过登陆直接进入主界面
if(empty($_SESSION["UserName"]))
{
  header("location:denglu.php");
  exit;
}
  
require "DBDA.class1.php";
$db = new DBDA();
$UserName = $_SESSION["UserName"];
?>
<div>
<a href="fabu.php">发布信息</a>
<a href="tuichu.php">退出系统</a>
</div><br /><br />
<h2>留言信息:</h2>
<table width="100%" border="1" >
  <tr>
    <td>发送人</td>
    <td>发送时间</td>
    <td>接收人</td>
    <td>信息内容</td>
  </tr>
   <?php
  
  //显示接收者是我的,或者是所有人的
  $sql = "select * from liuyan where Recever='{$UserName}' or Recever='suoyou'";
  $arr = $db->query($sql);
  foreach($arr as $v)
  {
  
     echo "<tr>
          <td>{$v[1]}</td>
        <td>{$v[3]}</td>
        <td>{$v[2]}</td>
        <td>{$v[4]}</td>
        </tr>";
  }
  
  ?>  

</table>
</body>
</html>

2.tuichu.php

<?php
session_start();
unset($_SESSION["UserName"]);
header("location:denglu.php");

三.发送页面(fabu.php   fabuchuli.php)

php怎样实现留言板功能

1.fabu.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<div>
<a href="main.php">查看信息</a>
<a href="tuichu.php">退出系统</a>
</div>
<h2>信息发送:</h2>
<form action="fabuchuli.php" method="post">
<div>接收人:
<select name="jsr">
  <option value="suoyou">所有人</option>
  <?php
  session_start();
  $UserName = $_SESSION["UserName"];
  require"DBDA.class1.php";
  $db = new DBDA();
  //方法一
  $sql = "select friend.Friend,yuangong.Name from friend,yuangong where friend.Friend = yuangong.UserName and friend.Me = '{$UserName}'";
  $arr = $db->query($sql);
    
  foreach($arr as $v)
  {
    echo "<option value='{$v[0]}'>{$v[1]}</option>";
  }
  //方法二
  /*$sql = "select Friend from friend where Me ='{$UserName}'";
  $arr = $db->query($sql);
  foreach($arr as $v)
    {
      $v[0];
      $sname = "select Name from yuangong where UserName = '{$v[0]}'";
      $aname = $db->query($sname);
      echo"<option value='{$v[0]}'>{$aname[0][0]}</option>";
    }*/
  ?>        
</select></div>
<div>信息内容:<textarea name="neirong"></textarea></div>
<input type="submit" value="发送" />
<a href="fabu.php" ><input type="button" value="复位" /></a>
</form>
</body>
</html>

2.fabuchuli.php

<?php
session_start();
$UserName = $_SESSION["UserName"];
$jsr = $_POST["jsr"];
$nr = $_POST["neirong"];
$Times = date("Y-m-d H:i:s");


require"DBDA.class.php";
$db = new DBDA();
$sql = "insert into liuyan values('','{$UserName}','{$jsr}','{$Times}','{$nr}')";
$db->query($sql,0);
header("location:fabu.php");

关于“php怎样实现留言板功能”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php
AI