接着昨天写的,今天实现了添加新闻,编辑新闻,删除新闻等,
在index.php中:
switch($action){
case "addnewsview":
//采取第二种办法,到pluiew":
$tpl->assign("page_title","添加新闻");
$tpl->assign("content_title","添加新闻管理");
$tpl->assign("actionvalue","addnews");
//editor("FCK","");
$tpl->assign("editor",editor("content",""));
$tpl->display("addnews.html");
break;
case "delnews":
@$check=$_POST['check'];
//$id=$_REQUEST['id'];
//$tpl->assign("content_title","新闻管理");
//$tpl->assign("page_title","新闻管理系统");
for($i=0;$i<count($check);$i++){
$sql="delete from news where id='{$check[$i]}'";
$mysqli->query($sql);
}
header("location:index.php?action=''");
break;
case "addnews":
$title=$_POST['title'];
$content=$_POST['content'];
@$sql="insert into news(author,title,content,datetime) values('{$_SESSION[username]}','{$title}','{$content}',now())";
$mysqli->query($sql);
$tpl->assign("content_title","新闻管理");
$tpl->assign("actionvalue","delnews");
$tpl->assign("page_title","新闻管理系统");
$tpl->assign("username",$_SESSION['username']);
$tpl->display("index.html",$current_page);
break;
case "editor":
$id=$_GET['id'];
$sql="select id,title,content,datetime from news where id=".$id;
$result=$mysqli->query($sql);
$arr=$result->fetch_assoc();
$tpl->assign("page_title","编辑新闻");
$tpl->assign("content_title","编辑新闻管理");
$tpl->assign("editor",editor("content",$arr['content']));
$tpl->assign("title",$arr['title']);
$tpl->assign("id",$arr['id']);
$tpl->display("editor.html");
break;
case "save":
$id=$_POST['id'];
$title=$_POST['title'];
$content=$_POST['content'];
$sql="update news set title='{$title}',content='{$content}' where id={$id}";
$mysqli->query($sql);
header("location:index.php?action=''");
break;
default:
$tpl->assign("content_title","新闻管理");
$tpl->assign("actionvalue","delnews");
$tpl->assign("page_title","新闻管理系统");
$tpl->assign("username",$_SESSION['username']);
$tpl->display("index.html",$current_page);
}
在templates下创建addnews.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><{$page_title}></title>
<style type="text/css">
body{
margin-left:50;}
</style>
</head>
<{config_load file="foo.conf" section=$style}>
<body style="background-image:url(<{#background#}>)">
<p><{$content_title}><p>
<hr>
<table width="1000" height="500" border="0" align="center">
<tr>
<td>系统管理</td>
<td rowspan="2">
<form name="myform" method="post">
<p>标题:<input name="title" type="text"></p>
<p>内容:
<{$editor}></p>
<input type="submit" name="submit" value="提交">
<input type="hidden" name="action" value="<{$actionvalue}>">
<!--<input type="hidden" name="id" value="<{$id}>">-->
</form>
</td>
</tr>
<tr>
<td>添加新闻</td>
</tr>
</table>
</body>
</html>
在创建editor.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><{$page_title}></title>
<style type="text/css">
body{
margin-left:50;}
</style>
</head>
<{config_load file="foo.conf" section=$style}>
<body style="background-image:url(<{#background#}>)">
<p><{$content_title}><p>
<hr>
<table width="1000" height="500" border="0" align="center">
<tr>
<td>系统管理</td>
<td rowspan="2">
<form name="myform" method="post" action="index.php?action=save">
<input type="hidden" name="id" value="<{$id}>">
<p>标题:<input name="title" type="text" value="<{$title}>"></p>
<p>内容:
<{$editor}></p>
<input type="submit" name="submit" value="提交">
<!--<input type="hidden" name="id" value="<{$id}>">-->
</form>
</td>
</tr>
<tr>
<td>添加新闻</td>
</tr>
</table>
</body>
</html>
就这样,添加,编辑,删除新闻就实现了。