Smarty简单留言本
时间:2009-01-13
来源:互联网
目录树:
|---smarty
|---libs(模板文件夹)
|---fck
|---cache
|---configs
|---templates_c
|---templates
|-----includes
|---config.php(在此修改数据库配置)
|---.....
|---index.php
创建数据库gbook(编码是UTF8),导入gbook.sql,修改好自己的数据库配置即可运行~
[php]<?php
require_once('./includes/function.inc.php');
$db = new db_mysql;
$smarty = new Smarty_Gbook;
$smarty->caching = 0;
$action = $_GET['action'];
//这个判断实际上不起作用 :(
if(!$smarty->is_cached('index.tpl')){
$result = $db->query("select * from gbook order by gbook_id desc");
while($rs = $db->fetch_array($result)){
$gbooklist[]=$rs;
}
$smarty->assign('gbooklist', $gbooklist);
//$smarty->cache_lifetime = 100;
}
switch($action){
//添加留言
//-----------------------------------------------------------------------
case "add":
$smarty->assign('action','adds'); //设置为添加状态
$smarty->assign('type','add'); //type可以是不为空的任意值
$smarty->editor('gbook_content'); //编辑器
break;
case "adds":
//接收数据
$gbook_name = $_POST['gbook_name'];
$gbook_qq = $_POST['gbook_qq'];
$gbook_content= $_POST['gbook_content'];
$gbook_time = time();
if(empty($gbook_name) || empty($gbook_qq) || empty($gbook_content)){
showerr("请填写完整!");
}
//写入
$rs = $db->query("insert into gbook (`gbook_name`,`gbook_qq`,`gbook_content`,`gbook_time`) value ('$gbook_name', '$gbook_qq', '$gbook_content', '$gbook_time')");
if($rs){
ShowMsg("添加成功!", '?', 500);
exit;
}else{
showerr("添加出错!");
}
break;
//修改留言
//-----------------------------------------------------------------------
case "edit":
//接收ID
$gbook_id = $_GET['id'];
//查询要编辑的留言
$result = $db->query("select * from gbook where gbook_id=$gbook_id");
$rs = $db->fetch_array($result);
$smarty->assign('action','edits'); //设置为编辑状态
$smarty->assign('type','edit'); //type可以是不为空的任意值
$smarty->assign('gbook_id',$rs[gbook_id]);
$smarty->assign('gbook_name',$rs[gbook_name]);
$smarty->assign('gbook_qq',$rs[gbook_qq]);
$smarty->editor('gbook_content',$rs[gbook_content]);
break;
case "edits":
$gbook_id = $_POST['id'];
$gbook_name = $_POST['gbook_name'];
$gbook_qq = $_POST['gbook_qq'];
$gbook_content= $_POST['gbook_content'];
if(empty($gbook_name) || empty($gbook_qq) || empty($gbook_content)){
showerr("请填写完整!");
}
$rs = $db->update("update gbook set gbook_name='$gbook_name', gbook_qq='$gbook_qq', gbook_content='$gbook_content' where gbook_id=$gbook_id");
if($rs){
ShowMsg("修改成功!", '?', 500);
exit;
}else{
showerr("修改出错!");
}
break;
//删除留言
//-----------------------------------------------------------------------
case "delete":
$gbook_id = $_GET['id'];
if($db->query("delete from gbook where gbook_id=$gbook_id")){
ShowMsg("删除成功!", '?', 500);
exit;
}else{
showerr("删除出错!");
}
break;
}
//显示模版
$smarty->display('index.tpl');
?>[/php]
aaa.GIF (52.66 KB)
作者: baln 发布时间: 2009-01-13
作者: 111 发布时间: 2009-01-13
作者: Rcook 发布时间: 2009-01-13
作者: CFC4N 发布时间: 2009-01-15
作者: liumingchen 发布时间: 2009-01-15
那个网页IP好猥琐啊!
作者: baln 发布时间: 2009-01-15
作者: sipangg 发布时间: 2009-01-16
那个网页IP好猥琐啊!
作者: hubo888168 发布时间: 2009-02-01



作者: hi_listen 发布时间: 2009-02-20
作者: suchshow 发布时间: 2009-02-22
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28