小型bbs论坛系统开发4 后台父板块添加/修改

本章主要学习了,统一验证处理及验证处理机制,我觉得还是比较重要的。

项目布局:
–father.module.add.php
–father.module.update.php
–inc/check.father.module.inc.php


父板块页 father.module.php:

<?php 
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
$title = '父板块列表';//设置当前页面标题

$link = sql_connect();

?>

<?php include_once './inc/header.inc.php'; ?>
    <div id="main" style="height:1000px;">
        <div class="title">父板块信息</div>
        <table class="list">
            <tr>
                <th>排序</th>         
                <th>版块名称</th>
                <th>操作</th>
            </tr>

            <?php 
            $query ="select * from sfk_father_module";
            $result = sql_execute($link,$query);
            while($data = mysqli_fetch_assoc($result)){
                // 实际删除代码:
                // father.module.delete.php?id={$data['id']}
                $url =urlencode("father.module.delete.php?id={$data['id']}");
                $returnUrl = urlencode($_SERVER['REQUEST_URI']);
                $deleteUrl = "confirm.php?url={$url}&returnUrl={$returnUrl}";
$html=<<<STRING
            <tr>
                <td><input class="sort" type="text" name="sort" /></td>
                <td>{$data['module_name']} id:[{$data['id']}]</td>
                <td>
                    <a href="#">[访问]</a>&nbsp;&nbsp;
                    <a href="father.module.update.php?id={$data['id']}&module_name={$data['module_name']}&sort={$data['sort']}">[编辑]</a>&nbsp;&nbsp;
                    <a href="{$deleteUrl}">[删除]</a>
                </td>
            </tr>
STRING;
            echo $html;
            }
            ?>


        </table>
    </div>  

<?php include_once './inc/footer.inc.php'; ?>

父板块添加页 father.module.add.php:

<?php 
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
include_once '../inc/tool.inc.php';
$title = '父板块添加';//设置当前页面标题

if(isset($_POST['submit'])){
    $link = sql_connect();
    $check_flag = 'add';//执行sql操作的方式
    //验证表单验证文件:
    include_once './inc/check.father.module.inc.php';

    // 执行插入操作
    $query = "insert into sfk_father_module(module_name,sort) values('{$_POST['module_name']}',{$_POST['sort']})";
    sql_execute($link,$query);
    if(mysqli_affected_rows($link) == 1){
        skip('father.module.php','ok','添加父板块成功!');
    }else{
        skip('father.module.php','error','添加父板块失败!');
    }
}

?>


<?php include_once './inc/header.inc.php';?>

    <div id="main" style="height:1000px;">
        <div class="title" style='margin-bottom:20px;'>父板块添加</div>
        <form method="POST">
            <table class="au">
                <tr>
                    <td>版块名称</td>
                    <td><input type="text" name = 'module_name'/></td>
                    <td>最大长度不得超过32个字符</td>
                </tr>
                <tr>
                    <td>排序</td>
                    <td><input type="text" name = 'sort' value = '0' /></td>
                    <td>只能填写数字</td>
                </tr>
            </table>
            <input class="btn" type="submit" name="submit" value="添加" style='margin-top: 10px;'/>
        </form>
    </div>

<?php include_once './inc/footer.inc.php'; ?>

父板块修改页 father.module.update.php:

<?php 
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
include_once '../inc/tool.inc.php';
$title = '父板块修改';//设置当前页面标题

$link = sql_connect();
//获取表单默认值
$query = "select * from sfk_father_module where id = '{$_GET['id']}'";
$result = sql_execute($link,$query);
$data = mysqli_fetch_assoc($result);

if(!isset($_GET['id']) || !isset($_GET['module_name']) || !isset($_GET['sort'])){
    skip('father.module.php','error','当前url来路不明');
}
if(!is_numeric($_GET['id'])){
    skip('father.module.php','error','id参数传递失败');
}
if(isset($_POST['submit'])){
    //验证表单验证文件:
    $check_flag = 'update';
    include_once './inc/check.father.module.inc.php';
    $query ="update sfk_father_module 
             set module_name ='{$_POST['module_name']}',sort = {$_POST['sort']} 
             where id = {$_GET['id']}";
    sql_execute($link,$query);

    if($_POST['module_name'] == $_GET['module_name'] && $_POST['sort'] == $_GET['sort']){
        skip('father.module.php','ask','您没有做任何更改');
    }
    if(mysqli_affected_rows($link) == 1){
        skip('father.module.php','ok','修改父板块成功!');
    }else{
        skip('father.module.php','error','修改父板块失败!');
    }
}

?>
<?php include_once './inc/header.inc.php';?>
    <div id="main" style="height:1000px;">
        <div class="title" style='margin-bottom:20px;'>父板块修改</div>
        <form method="POST">
            <table class="au">
                <tr>
                    <td>版块名称</td>
                    <td><input type="text" name = 'module_name' value = '<?php echo $data['module_name'];?>' /></td>
                    <td>最大长度不得超过32个字符</td>
                </tr>
                <tr>
                    <td>排序</td>
                    <td><input type="text" name = 'sort' value = '<?php echo $data['sort'];?>' /></td>
                    <td>只能填写数字</td>
                </tr>
            </table>
            <input class="btn" type="submit" name="submit" value="修改" style='margin-top: 10px;'/>
        </form>
    </div>
<?php include_once './inc/footer.inc.php'; ?>

这里写图片描述


这里写图片描述


这里写图片描述


这里写图片描述


这里写图片描述


这里写图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值