国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Article classification added function

1, write article categories and add templates

Create a new categoryListHtml.php file, the code is as follows:

<?php
header("Content-Type:text/html;charset=utf-8");
?>
<h1>后臺文章分類管理</h1>
<!--添加文章分類功能-->
<form action="?action=add" method="post">
    分類名稱:<input type="text" name="name">
    <input type="submit" value="添加">
</form>

The interface is shown as follows :

微信圖片_20180306151229.png

2, enter the category information to submit the form

Create a new category.php file Get the data submitted by the form, and then write the data into the database. The specific code is as follows:

<?php
require('./init.php');
//獲取操作標識
$a=isset($_GET['action'])?$_GET['action']:"";
//文章分類具體功能
if($a=='add'){
    $data['name']=trim(htmlspecialchars($_POST['name']));
    //判斷分類名稱是否為空
    if($data['name']===''){
        $error[]='文章分類名稱不能為空!';
    }else{
        //判斷數(shù)據(jù)庫中是否有同名的分類名稱
        $sql="select id from cms_category where name=:name";
        if ( $db->data($data)->fetchRow($sql)){
            $error[]="該文章分類已存在";
        }else{
            //插入到數(shù)據(jù)庫
            $sql="insert into cms_category(name)values(:name)";
            $db->data($data)->query($sql);
        }
    }
}
}
require './categoryListHtml.php';

Click to add:

微信圖片_20180306152710.png

##The database is displayed as follows:

微信圖片_20180306152841.png

微信圖片_20180306152710.png

Click to add and observe the database information:


Continuing Learning
||
<?php echo "文章分類添加功能";
submitReset Code