Module introduction to the website backend - Category management (4) Modify and delete categories
This section will introduce a very important link, classification management, which is the core of writing a website.
What is classification management? Classification management refers to classifying things into categories, and applying different or similar management methods to different categories.
Create cateedit.php and delete.php respectively under admin. The codes are as follows:
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'); } ?>
The modification and deletion of category management is completed, isn’t it very simple!