| 数据库
  
  
  1.登录界面登录界面实现账号、密码匹配数据库登录。登陆成功则跳转到首页page.html。
  demo1.html <html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<title>demo1</title>
</head>
<body>
	<form method ="POST" action="demo1.php">
	<center><h1>登录</h1> 
	账号:<input type="text" name="username"></input>
	<br>
	密码:<input type="password" name="passwd"></input>
	<br>
	<br>
	<input type="submit" value="登录"></input>
	</form>
</body>
</html>
 demo1.php <?php
	$host="127.0.0.1";
	$id="root";
	$pwd="123456";
	$database="test";
	$conn=mysqli_connect($host,$id,$pwd,$database);
	
	if($conn==true)	
	{
		echo "connect success<br>";
		$username=$_POST['username'];
		$password=$_POST['passwd'];
		$sql="select * from users where username='".$username."' and password='".$password."'";
		$result=mysqli_query($conn,$sql);
		if($result==false)
			echo "false";
		else {
			$items=mysqli_fetch_all($result);
			if(count($items)>=1)
			{
				echo "usename and password is right<br>";
				$times=time()+30*60;
				session_start();
				$_SESSION['name']="zhangsan";
				
				header("Location:http://127.0.0.1/index.php");
			}
			else {
				echo "usename and password is false<br>";
				header("refresh:2;url=./demo1.html");
			}
		}
	}
	else echo "connect false<br>";
?>
 退出链接到登录界面demo1.html。Quit.php
 <?php
	header("refresh:1;url=./demo1.html");
	exit();
?>
 2.首页界面如图所示,有三个链接,查看可跳转到show.php,添加可跳转到add.html,退出跳转到登陆界面demo1.html。
  Page.html <html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<title>首页</title>
</head>
<body>
<center>
	<div  >
		<img src="https://img1.baidu.com/it/u=1951064073,473148609&fm=253&fmt=auto&app=138&f=JPEG?w=470&h=500">
	</div>
	<div style="margin-center;margin-top:-360px;height:20px;width:250px" >
		<h1 >留言板</h1>
	</div>
	<div style="margin-top:100px" >
		<a href="./show.php">查看</a>
	</div>
	<div style="margin-top:75px" >
		<a href="./add.html">添加</a>
	</div>
	<div style="margin-top:50px" >
		<a href="./quit.php">退出</a>
	</div>
</body>
</html>
 3.查看留言界面如图所示,以列表的形式显示message表中的记录,可对每条记录进行删除的操作。刷新列表即可刷新该页面,返回可跳转到首页page.html。 
 Show.php <center>
<h1>留言列表</h1>
<hr>
<table border = "1" width = "700" >
    <tr>
        <th>留言id</th>
        <th>留言时间</th>
        <th>留言内容</th>
        <th>操作</th>
    </tr>
	<?php
		header("Content-type: text/html; charset=utf-8");
		$servername = "localhost";
		$username = "root";
		$password = "123456";
		$dbname = "test";
		$conn = new mysqli($servername, $username, $password, $dbname);
		if ($conn==false) {
			die("连接失败: " . $conn->connect_error);
		}
		$sql = "SELECT id, date, content FROM message";
		$result = mysqli_query($conn,$sql);
		if (mysqli_num_rows($result) > 0) {
			while($row = $result->fetch_assoc()) {
				echo "<tr style='text-align: center'>";
				echo "<td>{$row["id"]}</td>";
				echo "<td>{$row["date"]}</td>";
				echo "<td>{$row["content"]}</td>";
				echo "<td><a href='delete.php?id={$row['id']}'>删除</a></td>";
				echo "</tr>";
				echo "<br/>";
			}
		}
		else {
			echo "0 结果";
		}
			$conn->close();
	?>
</table><br>
<center>
<a href="show.php">刷新列表</a><br><br>
<a href="page.html">返回</a>
 删除后显示并跳转回原页面,如图所示。 
 Delete.php <?php
	header("Content-type: text/html; charset=utf-8");
	$servername = "localhost";
	$username = "root";
	$password = "123456";
	$dbname = "test";
	$conn = new mysqli($servername, $username, $password, $dbname);
	if ($conn==false) 
	{    
die("连接失败: " . $conn->connect_error);   
 }
	mysqli_query($conn,"DELETE FROM message WHERE id={$_GET['id']}");
	echo '删除成功!3秒后刷新页面...';
	header("refresh:3;url=./show.php");
	mysqli_close($conn);
?>
 4.添加留言界面如图所示,选择日期和输入留言后,点击提交。返回链接上一个页面。
  Add.html <html >
<head>
    <meta charset="UTF-8">
    <title>add</title>
</head>
<body>
<form action="add.php" method="post">
    <div>
        <center><h1>发布留言</h1> 
        <div>
            请选择日期:<input type="date" name="date">
			<br><br>
            请输入留言:<input type="textarea" size="15" name="message">
            <br><br>
            <div >
                <input type="submit" value="提交">
            </div>
        </div> <br>
		<a href="show.php">查看留言</a><br><br>
		<a href="page.html">返回</a>
    </div>
</form>
</body>
</html>
 Add.php <?php
	header("Content-type: text/html; charset=utf-8");
	$date = $_POST['date'];  	$message = $_POST['message'];
	$servername = "localhost";
	$username = "root";
	$password = "123456";
	$dbname = "test";
	$conn = new mysqli($servername, $username, $password, $dbname);
	if ($conn==false) {
		die("连接失败: " . $conn->connect_error);
	}
	global $message, $date;
	$sql = "INSERT INTO message (date, content) VALUES ('$date', '$message')";
	if ($conn->query($sql) === TRUE) {			echo '留言成功!3秒后刷新页面...';
		header("refresh:3;url=./add.html");
	} else {
		echo "Error: " . $sql . "<br>" . $conn->error;
	}	
	$conn->close();/
?>
 提交留言后,显示成功并跳转回原页面,如图所示。 
 |