smarty实现简单新闻管理系统

部分功能的实现

修改   
 case 'editnewsview' :
        $id = $_REQUEST['id'];  //获取修改id
     $query = "select * from news where id='$id'";
     $result = $db->query_exec($query);
     $arr = $result->fetch_assoc();
        $smarty->assign('page_title','新闻修改');
     $smarty->assign('title',$arr['title']);
     $smarty->assign('content',$arr['content']);
     $smarty->assign('id',$arr['id']);//重点
     editor('content',$arr['content']);//编辑器的内容
     $smarty->assign('actionvalue','editnews');
        $smarty->display('addnews.htm');
 break;
 case 'editnews' :
        $title = $_REQUEST['title'];
        $content = $_REQUEST['content'];
        $id = $_REQUEST['id'];
     $sql = "update news set title='$title', content='$content' , date=NOW() where id=$id ";
     if($db->query_exec($sql))
     {
     echo "修改成功!<meta http-equiv=\"Refresh\" content=\"1; url=./index.php\">";
     }
     else echo  "修改失败!<meta http-equiv=\"Refresh\" content=\"1; url=./index.php?action=editnewsview&id=$id\">";
      $db->close();
 break;

 

添加新闻

    case 'addnewsview' :
       $smarty->assign('page_title','新建新闻');
       $smarty->assign('actionvalue','addnews');
    editor('content',''); //调用编辑器,并定义文本域名为content(与下面addnews中的$_REQUEST['content']对应
    $smarty->display('addnews.htm');
 break;
 case 'addnews' :
       $title = $_POST['title'];
       $content = $_POST['content'];
    if(empty($title)|| empty($content))
    {
     echo "请填写完成!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php?action=addnewsview\">";
    }
    else
    {
       $sql = "insert into news(title,content,date) values('$title','$content', NOW())";//注意数据库的缺省
    if($db->query_exec($sql))
    {
      echo "添加成功!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php\">";
     }
     else
    {
   echo "添加失败!<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=./index.php?action=addnewsview\">";
   }
    }
   $db->close();
    break;

总结:

还有很多的不足,smarty的知识还要多多学习啊,差得远啊!


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值