Full code display of PHP development message board
List page:
<?php session_start(); header("content-type:text/html;charset=utf-8"); //連接數(shù)據(jù)庫 $link = mysqli_connect("localhost","root","root","message"); mysqli_set_charset($link,"utf8"); if (!$link) { die("連接失敗: " . mysqli_connect_error()); } //連接數(shù)據(jù)庫 $SQL = "SELECT * FROM DETAILS";//設(shè)置查詢指令 $result=mysqli_query($link,$sql);//執(zhí)行查詢 ?> <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="format-detection" content="telephone=no" /> <title>留言板</title> <style> .top{ width:410px } .fl{ float:left } .klytd {width:100px; text-align:left } </style> </head> <body> <div style="margin:0px auto;" class="top"> <!--頭部圖片--> <div class="head"> <img style="width:400px" src="https://img.php.cn/upload/course/000/000/007/5816db62346b9319.jpg"> </div> <!--中間內(nèi)容--> <div class="body"> <div style="width:400px;" class="fl font"> <div style="margin:0px auto;" class="keleyitable"><h2>留言列表</h2> <form method="post" action="list.php"> <?php while($row=mysqli_fetch_assoc($result)):?> <table> <tr><td class="klytd">留言時間:</td><td class="hvttd"><?php echo $row['time'];?></td></tr> <p> <button type="button" value="回復(fù)"> <a href="reply_list.php?id=<?php echo $row['id'];?>">回復(fù)</a> </button> </p> <tr><td class="klytd">留言人:</td><td class ="hvttd"><?php echo $row['name'];?></td></tr> <tr><td class="klytd">標(biāo)題:</td><td class ="hvttd"><?php echo $row['title'];?></td></tr> <tr><td class="klytd">內(nèi)容:</td><td class ="hvttd"><?php echo $row['content'];?></td></tr> <tr><td class="klytd">回復(fù):</td><td class="hvttd"><?php echo $row['reply'];?></td></tr> </table> </form> <br/> <hr> <?php endwhile;?> </div> <div> <button type="button" value="發(fā)表留言"><a href="form.html">發(fā)表留言</a></button> </div> </div> <!--底部鏈接與內(nèi)容--> <div> </div> </div> </body> </html>
Message page:
<?php session_start(); header("content-type:text/html;charset=utf-8"); //連接數(shù)據(jù)庫 $link = mysqli_connect("localhost","root","root","message"); mysqli_set_charset($link,"utf8"); if (!$link) { die("連接失敗: " . mysqli_connect_error()); } $name = isset($_POST['name'])?$_POST['name']:""; $title = isset($_POST['title'])?$_POST['title']:""; $content = isset($_POST['content'])?$_POST['content']:""; $time = date("Y-m-d H:i:s"); $sql ="insert into details(name,title,content,time) values('$name','$title','$content','$time')"; $rel = mysqli_query($link,$sql); if($rel){ echo"留言成功"."<br/><br/>"; echo"<a href='list.php'>跳轉(zhuǎn)至留言列表頁面</a>"; }else{ echo"留言失敗"."<br/><br/>"; echo"<a href='form.html'>跳轉(zhuǎn)至留言編輯頁面</a>"; } ?> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="format-detection" content="telephone=no" /> <title>留言板</title> <style> .w410{ width:410px } .mr_auto{ margin:0 auto; } .w400{ width:400px } </style> </head> <body> <div class="w410 mr_auto"> <!--頭部圖片--> <div> <img src="https://img.php.cn/upload/course/000/000/007/5816db62346b9319.jpg"> </div> <div style="padding-top: 30px;" class="mr_auto w400"> <form method="post" name="form1" id="form1" action="message.php"> 標(biāo)題:<input type="text" name="title"><br/><br/> 內(nèi)容:<textarea style="width:350px;height:200px;" name="content"></textarea><br/><br/> 作者:<input type="text" name="name"><br/><br/> <a href=""><input type="submit" style="margin-left:350px" value="提交"></a> </form> </div> </div> </body> </html>
Reply page:
<?php session_start(); header("content-type:text/html;charset=utf-8"); //連接數(shù)據(jù)庫 $link = mysqli_connect("localhost","root","root","message"); mysqli_set_charset($link,"utf8"); if (!$link) { die("連接失敗: " . mysqli_connect_error()); } $id = isset($_GET['id'])?$_GET['id']:""; $reply = isset($_POST['reply'])?$_POST['reply']:""; $sql ="update details set reply='$reply' where id=".$id; $rel = mysqli_query($link,$sql); if($rel){ echo"回復(fù)成功"."<br/><br/>"; echo"<a href='list.php'>跳轉(zhuǎn)至留言列表頁面</a>"; }else{ echo"回復(fù)失敗"."<br/><br/>"; echo"<a href='reply.html'>跳轉(zhuǎn)至回復(fù)編輯頁面</a>"; } ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="format-detection" content="telephone=no" /> <title>回復(fù)頁面</title> <style> .w410{ width: 410px; } .fon_f{ font-family: 微軟雅黑; } .pt{ padding-top: 80px; } </style> </head> <body> <div style="margin: 0 auto;" class="fon_f w410"> <div> <h1 style= "text-align:center;">留言窗口</h1> </div> <div style="margin: 0 auto;" class="pt lh"> <form name="form1" method="post" action="reply.php?id=<?php echo $_GET['id']?>"> 回復(fù):<textarea style="width: 380px;height: 200px;" name="reply"></textarea><br/><br/> <input type="submit" value="確認(rèn)回復(fù)"> </form> </div> </div> </body> </html>