哪里出了问题,deit获取不到数据

来源:1-6 作业题

慕侠6347478

2019-10-28 10:39:08

index

<?php
header('content-type:text/html;charset=utf-8');
date_default_timezone_set('PRC');
$filename="msg.txt";
$msgs=[];
//检查文件是否存在
if(file_exists($filename)){
   //读取文件内容
   $string=file_get_contents($filename);
   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($filename,$msgs)){
       echo "<script>alert('留言成功!');location.href='index.php'</script>";
   }else{
       echo "<script>alert('留言失败!');location.href='index.php'</script>";
   }
}
?>
<!doctype html>
<html lang="en">
<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>
                   IMOOC留言板-<small>v1.0</small>
               </h1>

           </div>
           <div class="hero-unit">
               <h1>
                   慕课留言板,欢迎你!
               </h1>
               <p>
                   <em>慕课网是垂直的互联网IT技能</em>免费学习网站。以独家视频教程、在线编程工具、学习计划、问答社区为核心特色。在这里,你可以找到最好<em>的互联网</em>技术牛人,也可以通过免费的在线公开视频课程学习国内领先<em>的互联网IT技</em>术。
               </p>

           </div>
           <?php if(is_array($msgs)&&count($msgs)>0): ?>
           <table class="table">
               <thead>
               <tr>
                   <th>
                       编号
                   </th>
                   <th>
                       用户名
                   </th>
                   <th>
                       标题
                   </th>
                   <th>
                       时间
                   </th>
                   <th>
                       内容
                   </th>
                   <th>
                       操作
                   </th>
               </tr>
               </thead>
               <tbody>
               <?php foreach($msgs as $key=>$val): ?>
               <tr class="success">
                   <td>
                       <?php echo $key+1;?>
                   </td>
                   <td>
                       <?php echo $val['username']; ?>
                   </td>
                   <td>
                      <?php echo $val['title']; ?>
                   </td>
                   <td>
                       <?php echo date("m/d/y H:i:s",$val['time']); ?>
                   </td>
                   <td>
                       <?php echo $val['content']; ?>
                   </td>
                   <td>
                       <a href="edit.php?editkey=<?php echo $key;?>">编辑</a>  | <a href="javascript:;" onclick="del(<?php echo $key ?>);return false;">删除</a>
                       <script type="text/javascript">
                           function del(key){
                               if(confirm("确定删除吗")){
                                   location.href="delete.php?delkey="+key;
                               }else{
                                   location.href="index.php";
                               }
                           }
                       </script>
                   </td>
               </tr>
               <?php endforeach; ?>
               </tbody>
           </table>
           <?php endif; ?>
           <a class="btn btn-primary btn-large" href="add.php">我要留言</a>
       </div>
   </div>
</div>
<hr>
<div class="footer">
   慕课商城© 2017 powered by <strong>IMooc.inc</strong>
</div>
</body>
</html>

edit

   $time=time();
   $date=compact('username','title','content','time');
   if(file_put_contents($filename,serialize($msgs))){
       echo "<script>alert('修改成功');location.href='index.php'</script>";
   }else{
       echo "<script>alert('修改失败');location.href='edit.php'</script>";
   }
}
?>
<!doctype html>
<html lang="en">
<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>
                   IMOOC留言板-<small>v1.0</small>
               </h1>

           </div>
           <div class="hero-unit">
               <h1>
                   既然来了,就说点什么吧~~~~
               </h1>
               <p>
                   把你想说的写在下边,标注好你的姓名,主题,点击提交发送给我们,让小伙伴们都知道你在想些什么
               </p>
           </div>
           <form action="edit.php" method="post">
               <legend>发布</legend>
               <label>用户名</label><input type="text" name="username" <?php echo $username1; ?> required/>
               <label>标题</label><input type="text" name="title" <?php echo $title1; ?>  required/>
               <label>内容</label><textarea name="content" id="" rows="5" cols="30" <?php echo $content1; ?> required></textarea><br>
               <input type="hidden" name="getZ" id="getZ" value="<?php echo $getZ; ?>"
               <input type="submit" value="编辑完成" name="pubMsg" class="btn btn-primary btn-lg"/>
               <a class="btn btn-lg" href="index.php">查看留言</a>
           </form>
       </div>
   </div>
</div>
</body>
</html>

写回答

2回答

好帮手慕小尤

2019-10-28

同学自己就可以寻找到问题所在,很赞哦~ 棒棒哒!继续加油!

0

慕侠6347478

提问者

2019-10-28

麻烦老师了,已经解决了。不知道为什么每次问了老师以后自己就找到问题...

0

0 学习 · 4928 问题

查看课程