您的位置:首页 > 其它

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

2016-12-19 16:34 337 查看
本章主要学习了,统一验证处理及验证处理机制,我觉得还是比较重要的。

项目布局:

–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>  
<a href="father.module.update.php?id={$data['id']}&module_name={$data['module_name']}&sort={$data['sort']}">[编辑]</a>  
<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
d780
="添加" 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'; ?>












内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: