成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導航首頁 ? 技術教程 ? 使用PHP連接數據庫實現留言板功能的實例講解(推薦)
全站頭部文字 我要出現在這里
使用PHP連接數據庫實現留言板功能的實例講解(推薦) 737 2023-12-10   

PHP實現留言板功能:

1 首先是登錄頁面:

<!DOCTYPE html>
<html>
 <head>
  <meta charset="UTF-8">
  <title>留言板登錄</title>
  <script src="http://www.gimoo.net/t/1712/bootstrap/js/jquery-1.11.2.min.js"></script>
  <script src="http://www.gimoo.net/t/1712/bootstrap/js/bootstrap.min.js"></script>
  <link  rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet" type="text/css"/>
 </head>
 <style>
  .header{
   margin-left: 550px;
   margin-top: 150px;
   height: 300px;
   max-width: 300px;
  }
  .xiugai{
   max-width: 200px;
  }
  .login{
   margin-top: 10px;
  }
 </style>
 <body>
  <form action="messloginchuli.php" method="post">
  <div class="header">
   <h2>開發部內部留言板</h2>
   <div class="input-group xiugai">
    <span class="input-group-addon" >用戶名:</span>
    <input type="text" class="form-control" name="uid" placeholder="請輸入用戶名">
   </div>
   <div class="input-group xiugai" >
    <span class="input-group-addon">口令:</span>
    <input type="text" class="form-control" name="pwd" placeholder="請輸入口令">
   </div>
   <button type="submit" class="btn btn-success login">登錄</button>
  </div>
 </form>
 </body>
</html>

2 登錄頁面完成后要進入登錄處理頁面了,也就是上面提交到的messloginchuli.php

<?php
session_start();  // 登錄之后要把所包含登錄的頁面連接起來,開啟session
$uid = $_POST["uid"];
$pwd = $_POST["pwd"];
require_once "./DBDA.class.php";
$db = new DBDA();
$sql = "select password from yuangong where username='{$uid}'";
$arr = $db->query($sql,0);
//var_dump($arr[0][0]);
if($arr[0][0]=$pwd && !empty($pwd)){
 $_SESSION["uid"]=$uid;
 header("location:message.php");
}

?>

登錄頁面效果如圖:

查看圖片

3.登錄完成后是進入主頁面,也就是顯示自己收到的對話內容,下面是設計的數據庫的表格和主頁面的代碼:

查看圖片

<!DOCTYPE html>
<html>
 <head>
  <meta charset="UTF-8">
  <title></title>
  <script src="http://www.gimoo.net/t/1712/bootstrap/js/jquery-1.11.2.min.js"></script>
  <script src="http://www.gimoo.net/t/1712/bootstrap/js/bootstrap.min.js"></script>
  <link  rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet" type="text/css"/>
 </head>
 <style>
  .mess{
   max-width: 800px;
   margin-left: 250px;
   margin-top: 150px;
  }
 </style>
 <body>
  <?php
  session_start();
  $uid = $_SESSION["uid"];
  if(empty($_SESSION["uid"])){
   header("location:messlogin.php");
   exit;
  }
  ?>
  <div >
   <a  rel="external nofollow" >發布信息</a>
   <a  rel="external nofollow" >退出系統</a>
   </div>
  <table class="table table-bordered mess" >
   <caption >
    留言信息:
   </caption>
   
   <thead>
    <tr>
     <th>發送人</th>
     <th>發送時間</th>
     <th>接收人</th>
     <th>信息內容</th>
    </tr>
   </thead>
   <tbody>
    <?php
    require_once "./DBDA.class.php";
    $db = new DBDA();
    $sql = "select * from liuyan where recever='{$uid}' or recever='all'";
    $arr = $db->query($sql,0);
    foreach($arr as $v){
     echo "<tr>
     <td>{$v[1]}</td>
     <td>{$v[2]}</td>
     <td>{$v[3]}</td>
     <td>{$v[4]}</td>
    </tr>";
    }
    ?>
    
   </tbody>
  </table>

 </body>
</html>

退出登錄系統實現用戶注銷,返回登錄頁面功能代碼如下:

 <?php
session_start();
$uid = $_SESSION["uid"];
unset($uid);
header("location:messlogin.php");

?>

代碼寫到這里,比較重要的部分就完成了,下面是要進入發布信息頁面了,相當于之前寫的添加的頁面,其處理頁面也是和之前沒什么區別的,差別在于現在的處理頁面是在用戶登錄的情況下操作的,需要用session把所有的登錄情況下的頁面連接起來

主頁面效果如圖:

查看圖片

查看圖片

4.最后是信息發布頁面,可以給任何人發送信息

代碼如下:

<!DOCTYPE html>
<html>
 <head>
  <meta charset="UTF-8">
  <title>發布信息界面</title>
  <script src="http://www.gimoo.net/t/1712/bootstrap/js/jquery-1.11.2.min.js"></script>
  <script src="http://www.gimoo.net/t/1712/bootstrap/js/bootstrap.min.js"></script>
  <link  rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet" type="text/css"/>
 </head>
 <style>
  .mess{
   max-width: 200px;
   margin-top: 10px;
  }
  .mess1{
   margin-top: 10px;
  }
  .opt{
   max-width: 200px;
   margin-left: 80px;
  }
  .txt{
   max-width: 200px;
  }
 </style>
 <body>
<?php
session_start();
$uid = $_SESSION["uid"];
if (empty($_SESSION["uid"])) {
 header("location:messlogin.php");
 exit ;
}
?>
 <div >
  <div >
   <a  rel="external nofollow" >查看信息</a>
   <a  rel="external nofollow" >查看發送信息</a>
   </div>
  <form class="form-horizontal" role="form" action="infochuli.php" method="post">
   
   <div class="form-group">
     <label for="firstname" class="col-sm-2 control-label mess1">接收人:</label>
     <div class="form-group ">
      <select class="form-control opt" name="recever">
       <option value="all">所有人</option>
      <?php
      
      require_once "./DBDA.class.php";
      $db = new DBDA(); 

       //這里可以給特定的朋友發送信息的sql語句
      //$sql = "select firend.firend,yuangong.name from firend,yuangong where firend.firend 
      //= yuangong.username and firend.me = '{$uid}'";
      $sname = "select * from yuangong where username not in ('{$uid}')";
      $arr = $db->query($sname,0);      
      //var_dump($arr[0][2]);
      foreach($arr as $v){
       echo "<option value='{$v[0]}'>{$v[2]}</option>";
      }
      ?>      
      </select>
     </div>
    </div>
   
   <div class="form-group">
    <label for="lastname" class="col-sm-2 control-label mess1">信息內容:</label>
    <div class="col-sm-10">
     <textarea class="form-control txt" rows="3" name="content"></textarea>
    </div>
   </div>
   <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
     <button type="submit" class="btn btn-default">
     發送
     </button>
    </div>
   </div>
  </form>
 </div>

 </body>
</html>

發信息頁面如圖:

查看圖片

5.發布信息完成后要進入處理頁面了,也就是提交到的infochuli.php,最后返回發送信息界面

<?php
session_start();
$uid = $_SESSION["uid"];
$recever = $_POST["recever"];
$content = $_POST["content"];
$arr = $_POST["recever"];
$t = date("Y-m-d H:i:s");
require_once "./DBDA.class.php";
$db = new DBDA();
$sql = "insert into liuyan values('','{$uid}','{$t}','{$recever}','{$content}',0)";
$arr = $db->query($sql);
if($arr && !empty($arr)){
 header("location:publish_info.php");
}else{
 echo "發送失敗!";
}

?>

以上這篇使用PHP連接數據庫實現留言板功能的實例講解(推薦)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持綠夏網。


主站蜘蛛池模板: cctv6电影节目表| 1—42集分集剧情简介| 豆花电影免费播放| 各各他的爱的歌谱| 假男假女| 日韩电影免费观| 我爱我爹全集高清版免费观看| 张勇手演过的电影| 故乡,别来无恙演员表| 集体生活成就我教学设计| 羞羞片| 高冷女头| 人民日报评墨茶| 漂亮孕妇突然肚子疼视频 | 西藏秘密演员表全部| 转正意见评语| 清水美里| 同志电影副歌1080p| 河南都市频道节目单| 荒笛子简谱| 男人不可以穷演员表| 大决战免费观看| 女人的战争剧情介绍| 天气预报电影| 怀孕肚脐眼凸起和凹进去有什么区别| 黄瀞怡| 美腿丝袜高跟三级视频| 假男假女 电影| 但愿人长久| 女子监狱第五季| 爆操女人逼| 贾宏| 羞羞答答av| 操蛋视频| 欧美乱淫av片免费黑鬼| 美人计电影国语免费观看| 爆操女人逼| 三年级片| 六年级上册脱式计算题| 汤姆·威尔金森| 践行者|

!!!站長長期在線接!!!

網站、小程序:定制開發/二次開發/仿制開發等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103