美文网首页
2019-05-06

2019-05-06

作者: 仙仙家的菜菜云 | 来源:发表于2019-05-06 16:34 被阅读0次

    留言板的开发总结


    策划书

    子主题 1

    安装功能 install

    连接数据库

    conn = mysqli_connect("localhost","root","root"); if(conn ){
    echo "数据库连接成功。";
    }else{
    echo "数据库连接失败。";
    }

    创建数据库guestbook

    sql = "CREATE DATABASE guestbook";result = mysqli_query(conn,sql);
    if( $result ){
    echo "数据库guestbook创建成功。";
    }else{
    echo "数据库guestbook创建失败。";
    }

    选择数据库guestbook

    mysqli_select_db($conn,"guestbook");

    创建留言内容表content

    sql = "CREATE TABLE content( id int auto_increment primary key, name char(10), qq char(10), content text, date_time date )";result = mysqli_query(conn,sql);
    if( $result ){
    echo "数据表content创建成功。";
    }else{
    echo "数据表content创建失败。";
    }

    创建配置信息表config

    sql = "CREATE TABLE config( id int auto_increment primary key, username char(10), password char(10), site_name char(30), other text )";result = mysqli_query(conn,sql);
    if( $result ){
    echo "数据表config创建成功。";
    }else{
    echo "数据表config创建失败。";
    }

    初始化数据表

    //初始化config表
    sql = "INSERT INTO config( username, password, site_name, other ) VALUES ( 'admin', 'admin888', '夏日留言板', '开发者:' )";result = mysqli_query(conn,sql);
    if( $result ){
    echo "数据表config初始化成功。";
    }else{
    echo "数据表config初始化失败。";
    }

    //初始化content表
    sql = "INSERT INTO content( name, qq, content, date_time ) VALUES ( '小狗狗', '356550896', '我是一楼,表跟我抢!', '2019-03-21 9:33:40' )";result = mysqli_query(conn,sql);
    if( $result ){
    echo "数据表content初始化成功。";
    }else{
    echo "数据表content初始化失败。";
    }

    提示安装状态并跳转

    echo "<script>alert('恭喜您,留言本安装成功!点确定跳转到留言本首页');location.href='index.php';</script>";

    发布留言liuyan.php/html

    留言界面

    一个表单,四个控件

    <table class="liuyan">
    <tr>
    <td height="40" colspan="2" align="center" valign="middle"><a href="index.php">首页</a></td>
    </tr>
    <tr>
    <td height="40" align="right" valign="middle">呢称:</td>
    <td height="40" align="left" valign="middle"><label for="name"></label>
    <input name="name" type="text" id="name" size="20" maxlength="20"></td>
    </tr>
    <tr>
    <td height="40" align="right" valign="middle">QQ:</td>
    <td height="40" align="left" valign="middle"><label for="qq"></label>
    <input name="qq" type="text" id="qq" size="20" maxlength="15"></td>
    </tr>
    <tr>
    <td height="40" align="right" valign="middle">留言:</td>
    <td height="40" align="left" valign="middle"><label for="content"></label>
    <script id="editor" type="text/plain" style="width:400px;height:150px;"></script>
    <script>UE.getEditor('editor');</script>
    </td>
    </tr>
    <tr>
    <td height="40"> </td>
    <td height="40" align="left" valign="middle"><input type="submit" name="button" id="button" value="留言"></td>
    </tr>
    </table>

    留言功能

    设置时区

    date_default_timezone_set("PRC");

    //获取当前计算机的日期和时间
    $date_time = date('Y-m-d h:i:s');

    接收留言内容

    name =_POST["name"];
    qq =_POST["qq"];
    content =_POST["editorValue"];

    把留言内容写入数据库

    //连接数据库
    include "conn.php";

    //选择数据库guestbook
    mysqli_select_db($conn,"guestbook");

    提示并跳转

    echo "<script>alert('恭喜您,留言成功!点确定跳转到留言本首页');location.href='index.php';</script>";

    显示留言index

    表格布局显示留言内容

    二行4列

    <table cellpadding="5" class="the_content">
    <tbody>
    <tr>
    <td height="30" align="center" valign="middle">第<?php echo the_content["id"]; ?>楼</td> <td height="30" align="center" valign="middle">呢称:<?php echothe_content["name"]; ?></td>
    <td height="30" align="center" valign="middle">QQ:<?php echo the_content["qq"]; ?></td> <td height="30" align="center" valign="middle">日期:<?php echothe_content["date_time"]; ?></td>
    <td align="center" valign="middle"><a href="edit.php?id=<?php echo the_content["id"]; ?>">编辑</a> | <a href="delete.php?id=<?php echothe_content["id"]; ?>">删除</a></td>
    </tr>
    <tr>
    <td colspan="5" align="left" valign="top"><?php echo $the_content["content"]; ?></td>
    </tr>
    </tbody>
    </table>

    查询数据库

    sql = "select * from content order by id desc limitstart,page_size";result = mysqli_query(conn,sql);

    拆数据包

    while ( the_content = mysqli_fetch_array(result) ){

    显示内容

    <?php echo $the_content["content"]; ?>

    分页admin

    理解并求出5个参数

    total_records:共多少条记录page_size:一个页面显示多少条记录
    page_current:当前是第几个分页url:要分页的地址
    $keyword:搜索关键词,如果不作搜索功能可为空

    调用函数

    include 'page.php';

    sql = "select * from content";result = mysqli_query(conn,sql);
    total_records = mysqli_num_rows(result);

    url =_SERVER['PHP_SELF'];

    $keyword = '';

    富文本编辑器ueditor

    百度的产品

    分别在头部和显示编辑器的地方,放上相应的脚本代码即可

    修改接收内容代码

    $_POST["editorValue"];

    登陆功能 do_login.php

    登陆界面

    一个表单,三个控件

    <table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td width="100" height="35" align="right" valign="middle">用户名:</td>
    <td><label for="username"></label>
    <input name="username" type="text" id="username" size="20" maxlength="20" /></td>
    </tr>
    <tr>
    <td width="100" height="35" align="right" valign="middle">密    码:</td>
    <td><label for="password"></label>
    <input name="password" type="password" id="password" size="20" maxlength="20" /></td>
    </tr>
    <tr>
    <td width="100" height="35" align="right" valign="middle"> </td>
    <td><input type="submit" name="button" id="button" value="登陆" /></td>
    </tr>
    </table>

    接收用户数据

    username =_POST["username"];
    password =_POST["password"];

    查询管理员账号

    include "conn.php";
    sql = "select username,password from config";result = mysqli_query(conn,sql);
    admin = mysqli_fetch_array(result);
    the_username =admin["username"];
    the_password =admin["password"];

    用户数据和管理员账号进行对比

    一致则登陆成功

    SESSION通行证

    session_start();

    提示并跳转到后台

    if( (username ==the_username) and (password ==the_password) ){
    echo "<script>alert('恭喜您,登陆成功!点确定跳转到留言本后台');location.href='admin.php';</script>";
    $_SESSION["login"] = "y";

    }

    不一致则登陆失败

    重新登陆

    else{
    echo "<script>alert('很遗憾,登陆失败!点确定跳转到登陆页面');location.href='login.html';</script>";
    $_SESSION["login"] = "n";
    }

    注销功能logout

    在后台设置注销链接

    <a href="logout.php">注销</a>

    设置一下SESSION通行证为非y值

    $_SESSION["login"] = "";

    提示并跳转到前台

    echo "<script>alert('注销成功!点确定跳转到留言本首页');location.href='index.php';</script>";

    内容管理

    显示内容

    增加删除,编辑链接入口

    <a href="edit.php?id=<?php echo the_content["id"]; ?>">编辑</a> | <a href="delete.php?id=<?php echothe_content["id"]; ?>">删除</a>

    加入门卫机制

    if( $_SESSION["login"] <> "y" ){
    echo "<script>alert('非法登陆!点确定跳转到留言本首页');location.href='index.php';</script>";
    }

    删除功能delete.php

    接收传递过来的id

    id =_GET["id"];

    执行删除功能的sql语句

    sql = "DELETE FROM content WHERE id=id";

    提示并跳转

    echo "<script>alert('删除成功,点确定跳到后台页面');location.href='admin.php';</script>";

    编辑功能edit

    编辑界面

    接收id

    id =_GET["id"];

    使用表单控件显示原来内容

    <table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td width="100" height="35" align="right" valign="middle">呢称:</td>
    <td><label for="name"></label>
    <input name="name" type="text" id="name" value="<?php echo the_content["name"]; ?>" size="20" maxlength="20" /></td> </tr> <tr> <td width="100" height="35" align="right" valign="middle">QQ:</td> <td><label for="qq"></label> <input name="qq" type="text" id="qq" value="<?php echothe_content["qq"]; ?>" size="20" maxlength="20" /></td>
    </tr>
    <tr>
    <td width="100" height="35" align="right" valign="middle">留言:</td>
    <td><label for="content"></label>
    <textarea name="content" id="content" cols="30" rows="7"><?php echo $the_content["content"]; ?></textarea></td>
    </tr>
    <tr>
    <td width="100" height="35" align="right" valign="middle"> </td>
    <td><input type="submit" name="button" id="button" value="编辑" /></td>
    </tr>
    </table>

    编辑功能

    接收新内容

    id =_POST["id"];
    name =_POST["name"];
    qq =_POST["qq"];
    content =_POST["content"];

    写入数据库

    /连接数据库
    include "conn.php";

    //写SQL语句
    sql = "update content set name='name',qq='qq',content='content' where id=id"; //执行sql语句 mysqli_query(conn,$sql);

    提示并跳转

    echo "<script>alert('编辑成功!点确定跳转到留言本后台');location.href='admin.php';</script>";

    美化

    HTML模板

    套用模板

    相关文章

      网友评论

          本文标题:2019-05-06

          本文链接:https://www.haomeiwen.com/subject/hirdoqtx.html