php-实例1:简单的文章管理系统

来源:互联网 发布:阿里云代理服务器 编辑:程序博客网 时间:2024/05/22 06:59

1.回顾:上篇学习了 php与mysql的一些基本操作函数

2.这篇将学习php实战1-简单的文章管理系统;

3.准备思路

    3.1 目的

            理解php操作mysql的具体方法,熟悉床用的php内置函数

    3.2  需求

   1)文章管理列表
   2)文章发布程序
   3)文章修改程序
  4)文章删除程序

    3.3 数据库设计:表 article:

            id   int  编号
            title  char 标题
            author  char 作者
   description  varchar 描述
            content  text 内容
            dateline  int 发布时间
  

4.配置文件 config.php

   通常使用常量来实现配置文件;定义常量
  header("Content-type:text/html;charset=utf-8");  define('HOST', 'localhost');  define('USERNAME', 'root');  define('PASSWORD','');


5. mysql 初始化程序

<?php/** * mysql 初始化 程序 * 01)连接数据库 * 02)选库 * 03)字符集 */  require_once 'Config.php'; if($conn=mysql_connect(HOST,USERNAME,PASSWORD)){ echo mysql_error(); }  if(mysql_select_db('test')){ echo mysql_error(); }  if(mysql_query('set names utf8')){ echo mysql_error(); }


6.新增文章实现

   页面实现html:
<?php header("Content-type:text/html;charset=utf-8");?><html><head>  <title>发布文章</title></head><body>   <form method="post" action="article.add.handle.php">       标题 : <input type="text" name='title' /> <br><br>   作者:   <input type="text" name='author' /><br><br>   描述:  <textarea  rows="4" cols="60" name='description'></textarea><br><br>   内容:  <textarea rows="15" cols="60" name='content'></textarea><br><br>        <input type="submit"  value="提交" /><br><br>       </form>  </body></html>

   业务实现:

<?php require_once('../connect.php'); $title=$_POST['title']; $author=$_POST['author']; $description=$_POST['description']; $content=$_POST['content']; $dateline=time(); $sql="insert into article(title,author,description,content,dateline) values( '$title','$author','$description','$content',$dateline)";//echo $sql; if(mysql_query($sql,$conn)){ echo "<h3>发布成功</h3> <br> <a href='article.list.php'>点击返回列表</a>"; }else { echo "<h3>发布失败</h3>".mysql_error(); }   


7. demo下载

  这里就只展示文章的发布功能,其余的增删改查等功能,就不展示了,需要的话,请下载demo!

   点我下载!http://download.csdn.net/detail/lablenet/8993665


8. 防止sql注入

  防止sql 注入,可以在传参数的时候,进行参数编码或者类型转换!











0 0
原创粉丝点击