웹사이트 백엔드 모듈 소개 ...LOGIN

웹사이트 백엔드 모듈 소개 - 카테고리 관리(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>
코스웨어