老师我的代码 都正确为什么 不能添加留言呢?

老师我的代码 都正确为什么 不能添加留言呢?

<?php 
header('content-type:text/html;charset=utf-8');
date_default_timezone_set('PRC');
$filname="chucun.txt";
$msgs=array();
if (file_exists($filname)) {
	//读取文件中的内容
	$string=file_get_contents($filname);
	//判断如果大于0代表有内容
	if(strlen($string)>0){
		//反序列化
		$msgs=unserialize($string);
	}
}
//检测用户是否点击了提交按钮?
if(isset($_POST['pubMsg'])){
	$username=$_POST['username'];
	$title=strip_tags($_POST['title']);
	$content=strip_tags($_POST['content']);
	$time=time();
	//快速将其组成关联数组
	$data=compact('username','title','content','time');
	array_push($msgs,$data);
	$msgs=serialize($msgs);
	//判断是否写入成功
	if(file_put_contents($filname,$msgs)){
		echo "<script>alert('留言添加成功');location.href='jiandanliuyanban.php'</script>";
	}else{
		echo "<script>alert('留言添加失败');location.href='jiandanliuyanban.php'</script>";
	};
};
?>
<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>
			<?php if(is_array($msgs) && count($msgs)>0):?>
			<table class="table nofollow">
				<thead>
					<tr>
						<th>
							编号
						</th>
						<th>
							用户
						</th>
						<th>
							标题
						</th>
						<th>
							时间
						</th>
						<th>
							内容
						</th>
					</tr>
				</thead>
				<tbody>
					<?php $i=1; foreach ($msgs  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 date("Y-m-d-H:i:s"),$value['time']; ?>
						</td>
						<td>
							<?php echo $value['content'];?>
						</td>
					</tr>
				<?php endforeach;?>
				</tbody>
			</table>
		<?php endif; ?>
		<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" class="btn" btn-primary btn-lg name="pubMsg" value="发表留言">
		</form>
</div>
</body>
</html>

麻烦老师帮我看看代码哪里错了。找了一晚上都没找出错误 麻烦老师帮我修改并标记一下错误的地方 谢谢了 感激不尽

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕查理 2019-03-08 10:43:08

您好,同学添加留言失败有提示信息吗?测试同学的代码留言是添加成功的。请同学详细描述不能添加的效果或者截图反馈,以便帮助同学查找原因。

http://img1.sycdn.imooc.com//climg/5c81d6110001831419000633.jpg

祝学习愉快!

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
PHP小白零基础入门
  • 参与学习           人
  • 提交作业       626    份
  • 解答问题       4928    个

想要学好Web后端开发的中流砥柱语言,本阶段为你轻松铺就扎实的基础,从前端网页布局的搭建到后台PHP开发,助你从零基础到掌握主流开发语言。

了解课程
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师