留言板编辑页面出现的问题

/Applications/MAMP/htdocs/phpstorm/edit.php:37:string 'a:1:{s:6:' (length=9)

这是我特地对$eidtkey var_dump出来的结果;

请问这个是什么原因造成的,该如何解决?目前只有第一条留言的$key可以获取,但是无法编辑,可以删除!

edit.php

<?phpdate_default_timezone_set('PRC');header('content-type:text/html;charset=utf-8');$editkey=$_GET['editkey'];$filename='msg.txt';$msgs=[];//检测文件是否存在if(file_exists($filename)){    //读取文件中的内容    $string=file_get_contents($filename);    if(strlen($string)>0){        $msgs=unserialize($string);    }}//检测用户是否点击提交按钮if(isset($_POST['sub'])){    $editkey=$_POST['edit'];    if($editkey==""){        echo "<script>alert('编辑失败,请重新编辑!');location.href='35-index.php';</script>";    }    $username=$_POST['username'];    $title=$_POST['title'];    $content=$_POST['content'];    $time=time();    $data=compact('username','title','content','time');    $msgs[$editkey] = $data;    $msgs=serialize($msgs);    if(file_put_contents($filename,$msgs)){        echo "<script>alert('编辑成功!');location.href='35-index.php';</script>";    }else{        echo "<script>alert('编辑失败!');location.href='35-index.php';</script>";    }    // array_push($msgs,$data);    // $msgs=serialize($msgs);    // var_dump($msgs);}var_dump($editkey);?><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>欢迎您!</span>Jokky</small>                </h1>            </div>            <div class="hero-unit">                <h1>                    Hello, world!                </h1>                <p>                    这是一个简易的留言板!                </p>            </div>            <hr/>            <form action="35-index.php" method="post">                <fieldset>                    <legend>留言板</legend>                    <label>用户名:</label><input type="text" name="username" placeholder="请输入姓名" value="<?php echo $msgs[$editkey]['username'];?>" required/>                    <label>标题:</label><input type="text" name="title" placeholder="请输入标题" value="<?php echo $msgs[$editkey]['title'];?>" required/>                    <label>内容:</label><textarea name="content" rows="5" cols="30" required><?php echo $msgs[$editkey]['content'];?></textarea>                    <hr/>                    <input type="submit" name="sub" value="编辑完成" class="btn btn-primary"/>                    <a href="#" class="btn btn-default">查看留言</a>                    <input type="hidden" name="edit" value="<?php echo $editkey;?>"/>                </fieldset>            </form>        </div>    </div></div></body></html>

35-index.php

<?phpheader('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);// }?><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>欢迎您!</span>Jokky</small>                </h1>            </div>            <div class="hero-unit">                <h1>                    Hello, world!                </h1>                <p>                    这是一个简易的留言板!                </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>                    <th>                        删除                    </th>                </tr>                </thead>                <tbody>                <?php $i=1; foreach ($msgs as $key=>$val): ?>                    <tr class="success">                        <td>                            <?php echo $i++;?>                        </td>                        <td>                            <?php echo $val['username'];?>                        </td>                        <td>                            <?php echo $val['title'];?>                        </td>                        <td>                            <?php echo date("Y/m/d H:i:s",$val['time']);?>                        </td>                        <td>                            <?php echo $val['content']?>                        </td>                        <td>                            <a href="edit.php?editkey=<?php echo $key?>" class="btn btn-danger" >编辑</a>                        </td>                        <td>                            <a href="delect.php?delect=<?php echo $key?>" class="btn btn-warning">删除</a>                        </td>                    </tr>                <?php endforeach; ?>                </tbody>            </table><?phpendif;?>            <hr/>            <a href="add.php" class="btn btn-primary">我要留言</a>        </div>    </div></div></body></html>


Jokky
浏览 813回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP