请教!这是个什么错误
来源:2-12 留言板功能实现
qq_ionicRoyKent_04116743
2017-04-25 15:25:33
3回答
好帮手慕查理
2017-04-27
您好,您的代码我们已经运行,并没有再报waring错误,请您检查一下其它代码。
qq_ionicRoyKent_04116743
提问者
2017-04-25
header('content-type:text/html;charset=utf-8'); date_default_timezone_set('PRC'); $filename="msg.txt"; $msgs = array(); //检测文件是否存在 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='22-msg.php';</script>"; }else{ echo "<script>alert('留言失败!');location.href='22-msg.php';</script>"; } } /*
我写的和讲师是一样的代码!为什么我会报这个错误
好帮手慕查理
2017-04-25
您好,第一个参数$msgs不是数组,所以报Warning错误。array_push()函数第一个参数为数组。如果解决了您的问题,请采纳,祝学习愉快!
相似问题