【使用云上托管RDS部署LAMP】


能插入数据并实时显示

资源清单

一、代码

1. index.php

<html>
  <head>
    <title>Hands-on Lab 动手实验室</title>
	<link rel="stylesheet" href="./src/main.css">
  </head>
  <body>
	
	<?php 
		ini_set("display_errors","On");
		$host = "";
		$db_account = "";
		$db_password = "";
		$db_connect = mysqli_connect($db_ip,$db_account,$db_password);
		mysqli_query($db_connect,"use lab;");
		$db_query = mysqli_query($db_connect,"SELECT * FROM myapp;");	
		$data = array();
		while($result = mysqli_fetch_array($db_query)){
			$data[] = $result;
		}
	?>
	
	<div class="content">
	  <div class="title">Hands-on Lab Timeline</div>
	</div>
	
	<div class="insert_block">
	  <fieldset>
	  <legend>添加数据</legend>
		<form action="./request.php" method="post">
		  <div class="row"><input type="text" name="name" value="" placeholder="请填写姓名,例如:zhangsan" /></div>
		  <div class="row"><input type="text" name="lab" value="" placeholder="请填写实验名称,例如:Lab1" /></div>
		  <div class="row"><button type="submit">增加数据</submit></div>
		</form>
	  </fieldset>
	</div>
	
	<div class="content">
	  <div class="title">Timeline 提交记录</div>
	  <div class="sub_title">
	    <?php 
		    $hostname = exec("hostname",$b);
			echo "ECS hostname: ".$hostname;
	    ?>
	  </div>
	  <table>
		<tr class="table_header">
		  <td width="28">序号</td>
		  <td width="100">时间</td>
		  <td width="100">实验</td>
		  <td width="100">同学</td>
		</tr>
		</tr>
		<?php 
			$index = 1;
			foreach($data as $item){
		?>
		<tr>
		  <td><?php echo $index++;?></td>
		  <td><?php echo @date("Y-m-d H:i:s",$item["created_at"]+8*3600);?></td>
		  <td><?php echo $item["lab"]?></td>
		  <td><?php echo $item["name"]?></td>
		</tr>
		<?php }?>
	  </table>
	</div>
  </body>
</html>

2. Request.php

<?php 

	$data = $_POST;
	
	$host = "";
	$account = "";
	$password = "";
	$db = "lab";
	$a = mysqli_connect($host,$account,$password);
	mysqli_query($a,"use lab;");
	
	$name = $data["name"];
	$lab = $data["lab"];
	$created_at = time();
	
	$sql = "INSERT INTO myapp(name,lab,created_at) value('".$name."','".$lab."','".$created_at."');";
	mysqli_query($a,$sql);
?>
<script>window.location.href="index.php"</script>

3. main.css (./src)

body {
	font-size: 14px;
}

.insert_block {
	width:1200px;
	margin:0px auto 20px;
	border:0px solid #CCCCCC;
	box-shadow: 5px 5px 10px #CCCCCC;
	padding:20px;
}

.row {
	padding: 6px 0;
}

input {
	padding: 6px 10px;
	margin: 10px 20px;
	width: 320px;
	font-size: 14px;
}

button {
	margin-left: 20px;
	background-color: #FF8800;
	color: #FFFFFF;
	border: none;
	padding: 10px 0px;
	width: 320px;
}

fieldset {
	border: 1px solid #FF8800;
}

.content {
	width: 1200px;
	margin: 0 auto;
	padding: 28px 0;
}

.title {
	padding: 0px 0 20px 0;
	font-size: 20px;
}

table {
	width: 100%;
	font-size:14px;
	line-height:28px;
}

.table_header {
	background-color:RGB(245,249,255);
}

.sub_title {
	padding: 0px 0 20px 0;
	font-weight:bold;
}

二、资源配置

云主机

RDS

效果

在这里插入图片描述

其他

https://www.php.cn/php-weizijiaocheng-226396.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值