结合数据库实现简单的留言板

数据库中新建的表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);
	
?>


实际界面如下
在这里插入图片描述
会跳转一个留言成功的界面
在这里插入图片描述
点击查看留言板
是真的丑 我尽力了
在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值