老师我的代码 都正确为什么 不能添加留言呢?
<?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>
麻烦老师帮我看看代码哪里错了。找了一晚上都没找出错误 麻烦老师帮我修改并标记一下错误的地方 谢谢了 感激不尽
0
收起
正在回答 回答被采纳积分+1
1回答
PHP小白零基础入门
- 参与学习 人
- 提交作业 626 份
- 解答问题 4928 个
想要学好Web后端开发的中流砥柱语言,本阶段为你轻松铺就扎实的基础,从前端网页布局的搭建到后台PHP开发,助你从零基础到掌握主流开发语言。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星