<div > <div><h2>PHP留言本</h2></div> <div> <volist> <div> <div> <span>留言者: {$vo.nickname}</span> <span>|</span> <span>邮箱: {$vo.email}</span> <span>时间: {$vo.replytime}</span> </div> <div> <span>内容: {$vo.content}</span> <span>{$vo.id}楼</span> </div> </div> </volist> </div> <div> <form method="post"> <div> <div> <div> <div> <input type="text" placeholder="游客姓名"/> </div> </div> <div> <div> <input type="text" placeholder="留言内容"/> </div> </div> <div> <span></span> <span> <input type="text" placeholder="Email"/> </span> </div> <div> <span><button>留言</button></span> <span><button>重置</button></span> </div> </div> </div> </form> </div> </div> <script> function clearDefaultText(){ var nickname = document.getElementById('nickname'); var content = document.getElementById('content'); var email = document.getElementById('email'); nickname.value=""; content.value=""; email.value=""; } </script>
PHP代码
public function hierarchicalauthority(){ if(isset($_POST['liuyan'])) { $data['nickname']=$_POST['nickname']; $data['content']=$_POST['content']; $data['email']=$_POST['email']; $data['status']=1; $data['replytime']=date('Y-m-d H:i:s',time()); // print_r($data);die(); $user=M('daili_liuyan_guestbook'); $maxid=$user->max('id'); $data['id']=$maxid+1; $user->add($data); // print_r($_POST);die(); } $guestbook = D('daili_liuyan_guestbook')->select(); $this->assign('guestbook',$guestbook); $this->display(); }
数据表:(表名为daili_liuyan_guestbook)
最终效果图: