日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php留言板实战,PHP留言本,非常适合新手实战操作!

發布時間:2024/9/15 php 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php留言板实战,PHP留言本,非常适合新手实战操作! 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

閑來沒事,應學習群里面一些人的要求,花了幾個小時寫了一個簡單的PHP留言本,很適合PHP新手學習,當然老手可以略過~~~~

架構:PHP+MYSQL+Layui+smarty,實現簡單的MVC構架,一個頁面完成留言本的增、刪、改、回復等功能。

文件目錄結構如下圖:

實現代碼就比較簡單了,總共100多行代碼實現。

class IndexController extends Site {

private $model;

private $DB;

public function __construct(){

parent::__construct();

$this->model=new Model();

$this->DB='www_message';

}

/**

* 首頁列表

*/

public function index(){

$page_size=3;//頁顯示數,根據自己需要調整

$pageCurrent=!empty($_GET["p"])?$_GET['p']:'1';

$currentNum=($pageCurrent-1)*$page_size;

$sql="select * from `".$this->DB."` ORDER BY id desc";

$query=$sql." limit $currentNum,$page_size";

$reccount=mysqli_num_rows($this->model->query($sql));

$list=$this->model->query($query);

$page=Pager('',$reccount,$page_size,$pageCurrent,10);

$this->assign('list',$list);

$this->assign('pager',$page);

$this->display('index.php');

}

//刪除留言操作

public function delete(){

$id=$_GET['id'];

$where['id']=$id;

$result=$this->model->delete($this->DB,$where);

if($result==true){

exit(json_encode(array('status'=>true,'info'=>'刪除成功')));

}else{

exit(json_encode(array('status'=>false,'info'=>'刪除失敗')));

}

}

/**

* 添加留言操作

*/

public function add(){

$postData=$_POST['info'];

$postData['create_time']=time();

$postData['uip']=get_client_ip();

$res=$this->model->inserttable($this->DB,$postData);

if($res){

exit(json_encode(array('status'=>true,'info'=>'留言成功')));

}else{

exit(json_encode(array('status'=>false,'info'=>'留言失敗')));

}

}

/**

* 回復留言

*/

public function edit(){

if($_SERVER['REQUEST_METHOD']=='POST'){

$postData=$_POST['info'];

$where['id']=$postData['id'];

unset($postData['id']);

$res=$this->model->updatetable($this->DB,$postData,$where);

if($res){

exit(json_encode(array('status'=>true,'info'=>'留言修改成功','isclose'=>true)));

}else{

exit(json_encode(array('status'=>false,'info'=>'留言修改失敗')));

}

}else{

$msgid=$_GET['id'];

$msgData=$this->model->getone('select `id`,`title`,`content` from `'.$this->DB.'` where id='.$msgid);

if(empty($msgData)){

exit('您查看的留言不存在或被刪除!');

}else{

$this->assign('msgdata',$msgData);

$this->display('edit.php');

}

}

}

/**

* 回復留言

*/

public function reply(){

if($_SERVER['REQUEST_METHOD']=='POST'){

$postData=$_POST['info'];

$postData['reply_time']=time();

$where['id']=$postData['id'];

unset($postData['id']);

$res=$this->model->updatetable($this->DB,$postData,$where);

if($res){

exit(json_encode(array('status'=>true,'info'=>'回復留言成功','isclose'=>true)));

}else{

exit(json_encode(array('status'=>false,'info'=>'回復留言失敗')));

}

}else{

$msgid=$_GET['id'];

$msgData=$this->model->getone('select * from `'.$this->DB.'` where id='.$msgid);

if(empty($msgData)){

exit('您查看的留言不存在或被刪除!');

}else{

$this->assign('msgdata',$msgData);

$this->display('reply.php');

}

}

}

}

以下是部分效果展示:

頁面功能比較簡單,暫未添加管理員管理留言功能,需要同僚的可以加群共同學習!

演示地址:http://www.phpteach.com/show/guestbook/

源碼可以到此處下載:?https://download..net/download/helly826/11372889

總結

以上是生活随笔為你收集整理的php留言板实战,PHP留言本,非常适合新手实战操作!的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。