为什么我写的留言板 只能保存一条留言呢?
来源:1-2 留言板功能实现
代码两万行
2019-03-07 20:36:08
<?php
$mm=[];
$filname="chucun.txt";
$username=$_POST['username'];
$title=$_POST['title'];
$content=$_POST['content'];
$data=compact('username','title','content');
array_push($mm,$data);
$mm=serialize($mm);
?>
<html>
<head>
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/jquery-2.0.0.min.js"></script>
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/jquery-ui"></script>
<link href="http://www.francescomalagrino.com/BootstrapPageGenerator/3/css/bootstrap-combined.min.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<div class="page-header">
<h1>
<small><span>PHP小练习之简易留言板</span></small>
</h1>
</div>
<table class="table nofollow">
<thead>
<tr>
<th>
编号
</th>
<th>
用户
</th>
<th>
标题
</th>
<th>
内容
</th>
</tr>
</thead>
<tbody>
<?php $i=1; foreach ($mm as $value):?>
<tr class="success">
<td>
<?php echo $i++;?>
</td>
<td>
<?php echo $value['username'];?>
</td>
<td>
<?php echo $value['title'];?>
</td>
<td>
<?php echo $value['content'];?>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
<form action="#" method="post">
<label>请留言</label>
<label>用户名</label><input type="text" name="username" required>
<label>标题</label><input type="text" name="title" required>
<label>内容</label><textarea name="content" rows="5" cols="30" required></textarea>
<hr>
<input type="submit" name="提交">
</form>
</div>
</body>
</html>老师我写的留言板为什么只能保存一条留言。如果继续留言 第二条留言就会替代第一条留言 留言板永远只有一条留言?麻烦老师帮我修改下代码 并说明下原因谢谢老师了
1回答
好帮手慕查理
2019-03-08
您好,同学提供的代码中并没有添加留言的操作,请同学提供添加留言的代码,以便查找添加留言会覆盖的原因。祝学习愉快!
相似问题