网站后台的模块介绍 - 分类管理(4)修改和删除分类
本节将会介绍一个非常重要的环节,分类管理,他是写一个网站的核心。
什么是分类管理?分类管理就是指将事物分门别类,针对不同的分类适用不同的或是类似的管理方法进行管理。
分别在admin下建立cateedit.php、delete.php,代码如下:
cateedit.php:
<?php
require_once("../config/config.php");
mysql_query("set names = utf8");
$sql = "SELECT * FROM cate";
if($_GET){
$cid = $_GET['cid'];
$sql0 = 'select cate_name from cate where cid ='.$cid;
$result =mysql_query($sql0);
$cate_name = mysql_fetch_assoc($result)['cate_name'];
}
if($_POST){
$id = $_POST['cid'];
$cate_name=$_POST["cate_name"];
$sql1 = 'select password from cate where cid='.$cid ;
$result = mysql_query($sql1);
$sql2 = 'UPDATE cate SET `cate_name`="'.$cate_name.'" where id ='.$cid;
mysql_query ($sql2);
header('location:./cate.php');
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<link rel="stylesheet" href="style/css/pintuer.css">
<link rel="stylesheet" href="style/css/admin.css">
<script src="style/js/jquery.js"></script>
<script src="style/js/pintuer.js"></script>
</head>
<body>
<div class="panel admin-panel margin-top">
<div id="add"><strong><span></span>修改分类</strong></div>
<div>
<form method="post" action="cateedit.php" enctype="multipart/form-data">
<div>
<div>
<label>分类名称:</label>
</div>
<input type="hidden" name="cid" value="<?php echo $cid;?>">
<div>
<input type="text" class="input w50" name="cate_name" value="<?php echo $cate_name;?>" />
<div></div>
</div>
</div>
<div>
<div>
<label></label>
</div>
<div>
<button class="button bg-main icon-check-square-o" type="submit"> 提交</button>
</div>
</div>
</form>
</div>
</div>
</body></html>delete.php:
<?php
require_once("../config/config.php");
$id = $_GET['id'];
$sql = "DELETE from user where id = ".$id;
$result = mysql_query($sql);
if($result){
header('location:./usermessage.php');
}
$sql1 = "DELETE from cate where id = ".$id;
$result1 = mysql_query($sql1);
if($result1){
header('location:./cateedit.php');
}
$sql3 = "DELETE from newbook where id = ".$id;
$result13 = mysql_query($sql3);
if($result3){
header('location:./newbook.php');
}
?>分类管理的修改和删除就完成了,是不是很简单!
