0%

[技能檢定]題組四 步驟13 製作後台會員管理功能

會員管理功能算是後台功能中較簡單的,而且大部份的程式碼都和管理權限設置相似,因此這邊建議是接在管理權限設置功能做完後順著做下來把它先完成。

  1. 複製 ./back/admin.php 的內容貼到 ./back/mem.php 中。
  2. ./back/mem.php 中依題目指示修改欄位及顯示內容
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    <h2 class="ct">會員管理</h2>
    <table class="all">
    <tr class="ct">
    <td class="tt">姓名</td>
    <td class="tt">會員帳號</td>
    <td class="tt">註冊日期</td>
    <td class="tt">操作</td>
    </tr>
    <?php
    //取出所有會員資料
    $rows=$Mem->all();
    //使用迴圈來取出資料
    foreach($rows as $row){
    ?>
    <tr class="ct">
    <td class="pp"><?=$row['name'];?></td>
    <td class="pp"><?=$row['acc'];?></td>
    <td class="pp"><?=$row['regdate'];?></td>
    <td class="pp">
    <!--使用js來跳轉頁面至修改功能,並帶上資料id-->
    <button onclick="location.href='?do=edit_mem&id=<?=$row['id'];?>'">修改</button>
    <button onclick="del('mem',<?=$row['id'];?>)">刪除</button>
    </td>
    </tr>
    <?php
    }
    ?>
    </table>
    <div class="ct">
    <button onclick="location.href='index.php'">返回</button>
    </div>

  1. 建立 ./back/edit_mem.php ,並撰寫編輯會員的表單頁面
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    <?php 
    //取出單筆會員資料
    $row=$Mem->find($_GET['id']);
    ?>
    <h2 class="ct">編輯會員資料</h2>
    <form action="./api/save_mem.php" method="post">
    <table class="all">
    <tr>
    <td class="tt ct">帳號</td>
    <td class="pp"><?=$row['acc'];?></td>
    </tr>
    <tr>
    <td class="tt ct">密碼</td>
    <!--密碼欄位使用*來代替-->
    <td class="pp"><?=str_repeat("*",strlen($row['pw']));?></td>
    </tr>
    <tr>
    <td class="tt ct">姓名</td>
    <td class="pp"><input type="text" name="name" value="<?=$row['name'];?>"></td>
    </tr>
    <tr>
    <td class="tt ct">電話</td>
    <td class="pp"><input type="text" name="tel" value="<?=$row['tel'];?>"></td>
    </tr>
    <tr>
    <td class="tt ct">住址</td>
    <td class="pp"><input type="text" name="addr" value="<?=$row['addr'];?>"></td>
    </tr>
    <tr>
    <td class="tt ct">電子信箱</td>
    <td class="pp"><input type="text" name="email" value="<?=$row['email'];?>"></td>
    </tr>
    </table>
    <div class="ct">
    <!--使用隱藏的表單欄位來傳遞資料id-->
    <input type="hidden" name="id" value="<?=$row['id'];?>">
    <input type="submit" value="編輯">
    <input type="reset" value="重置">
    <input type="button" value="取消" onclick="location.href='?do=mem'">
    </div>
    </form>

  1. 複製 ./api/save_admin.php ,並更名為 save_mem.php,修改相關的資料表名,及最後要導向的位置,即可完成編輯會員資料的功能。
    1
    2
    3
    include_once "../base.php";
    $Mem->save($_POST);
    to("../back.php?do=mem");