数据库中新建的表message
留言板界面布局
写留言界面
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>留言板</title>
<link rel="stylesheet" type="text/css" href="./js/bootstrap.min.css" />
<script type="text/javascript" src="./js/jquery-3.4.1.min.js"></script>
<script type="text/javascript" src="./js/bootstrap.min.js">
</script>
</head>
<body class="container">
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<a class="navbar-brand" href="#">留言板</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="show.php">查看留言板</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<form method="post" action="mb_1.php ">
<textarea class="form-control" rows="4" name="content"></textarea><br>
<button type="submit" class="btn btn-default" name="submit">留言</button>
</form>
</body>
</html>
连接数据库
<?php
$server="localhost";
$db_username="root";
$db_password="";
$con = @mysql_connect($server,$db_username,$db_password);//链接数据库
if(!$con){
die("can't connect".mysql_error());//如果链接失败输出错误
}
mysql_select_db('test01',$con);//选择数据库
?>
展示留言板
<?php
header("Content-Type: text/html; charset=utf8");
include("connect01.php");
$sql = "select *from message";
$result = mysql_query($sql,$con);
echo "<table border='1'>
<tr>
<th>ID</th>
<th>内容</th>
<th>发布日期</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['content'] . "</td>";
echo "<td>" . $row['lastdate'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
实际界面如下
会跳转一个留言成功的界面
点击查看留言板
是真的丑 我尽力了