網站後台的模組介紹 - 分類管理(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');
}
?>

分類管理的修改刪除就完成了,是不是很簡單!

繼續學習
||
<?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 lang="zh-cn"> <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 class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>修改分类</strong></div> <div class="body-content"> <form method="post" class="form-x" action="cateedit.php" enctype="multipart/form-data"> <div class="form-group"> <div class="label"> <label>分类名称:</label> </div> <input type="hidden" name="cid" value="<?php echo $cid;?>"> <div class="field"> <input type="text" class="input w50" name="cate_name" value="<?php echo $cate_name;?>" /> <div class="tips"></div> </div> </div> <div class="form-group"> <div class="label"> <label></label> </div> <div class="field"> <button class="button bg-main icon-check-square-o" type="submit"> 提交</button> </div> </div> </form> </div> </div> </body></html>
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!