利用PHP/MYSQL实现的简易微型博客(转)

数据库:ly_php_base

表:ly_micro_blog(仅仅有一个表)字段:id,title,date,content,hits

文件:

 

文件 描述
default.php 默认主页。显示博文与操作连接。
add.php 添加新博文的功能模块。
edit.php 对已经添加过的博文进行修改操作。
delete.php 删除博文模块。
view.php 显示博文的详细信息(标题|添加日期|浏览次数|内容)。
conn.php 链接数据库操作。在其它文件中被引用。

 

conn.php

php  
/** 
 *ly_micro_blog 
 *ID|TITLE|CONTENT|DATE 
 **/  
?>  
php  
//连接MySql数据库服务  
$conn = @mysql_connect("localhost:3306","root","228580") or die("连接数据库服务器失败!");  
//连接ly_php_base数据库  
@mysql_select_db("ly_php_base",$conn) or die("未能连接到数据库!");  
//mysql_query("SET NAMES 'GBK'");  
?>  
php  
include("conn.php");  
//搜索关键字的管理  
if(!empty($_GET['keys'])){  
    $keys = "WHERE title like '%".$_GET['keys']."%'";  
} else {  
    $keys = "";  
}  
$sql = "SELECT * FROM ly_micro_blog ".$keys." ORDER BY id DESC LIMIT 10";  
$query = mysql_query($sql);  
$rs = mysql_fetch_array($query);  
?>  
<html>  
<head>  
<title>我的微博客主页title>  
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>  
head>  
<body>  
<a href="add.php">添加内容a>  
<form action="" method="get">  
  <input type="text" name="keys"/>  
  <input type="submit" name="submit" value="内容搜索"/>  
form>  
<hr color="#FF9900" size="3" />  
php  
if(!$rs){  
    echo "没有相关内容!";  
}  
//没有实现分页导航功能  
while($rs){  
?>  
<h2>标题:php echo $rs['title'];?>|<a href="edit.php?id=">编辑a>|<a href="delete.php?id=">删除a>h2>  
<li>日期:php echo $rs['date'];?>li>  
<p>内容php echo iconv_substr($rs['content'],0,50,"UTF-8");?>...... <a href="view.php?id=">|查看详细内容|a>p>  
<hr color="#0033FF" size="5" />  
php  
    $rs = mysql_fetch_array($query);  
}  
?>  
body>  
html>

add.php

php  
//引入连接数据库文件  
include("conn.php");  
  
if(!empty($_POST['submit'])){  
    $title = $_POST['title'];  
    $content = $_POST['content'];  
    $sql = "INSERT INTO ly_micro_blog VALUES(NULL,'$title','$content',now())";  
    mysql_query($sql);  
}  
?>  
DOCTYPE HTML>  
<html>  
<head>  
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>  
<title>发布微博页面title>  
head>  
<body>  
<a href="default.php">查看内容a>  
<hr color="#0033CC" size="3px"/>  
<form action="add.php" method="post">  
  标题:  
  <input type="text" name="title"/>  
  <br />  
  内容:  
  <textarea rows="5" cols="50" name="content">textarea>  
  <br />  
  <input type="submit" name="submit" value="提交"/>  
  <br />  
form>  
body>  
html>  

edit.php

php   
include("conn.php");  
if(!empty($_GET['id'])){  
    $id = $_GET['id'];  
    $sql = "select * from ly_micro_blog where id = ".$_GET['id'];  
    $query = mysql_query($sql);   
    $rc = mysql_fetch_array($query);  
}  
  
if(!empty($_POST['update'])){  
    echo "更新按钮提交成功!";  
}  
?>  
  
DOCTYPE HTML>  
<html>  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
<title>编辑页面title>  
head>  
  
<body>  
<form action="edit.php?id=" method="post">  
  标题:  
  <input type="text" name="title" value=""/>  
  <br />  
  内容:  
  <textarea rows="5" cols="50" name="content">php echo $rc['content'];?>textarea>  
  <br />  
  <input type="submit" name="update" value="更新"/>  
  <br />  
form>  
body>  
html>  

delete.php

?php  
/** 
 *ly_micro_blog 
 *ID|TITLE|CONTENT|DATE 
 **/  
?>  
php  
//连接MySql数据库服务  
$conn = @mysql_connect("localhost:3306","root","228580") or die("连接数据库服务器失败!");  
//连接ly_php_base数据库  
@mysql_select_db("ly_php_base",$conn) or die("未能连接到数据库!");  
//mysql_query("SET NAMES 'GBK'");  
?>  

view.php

php   
include("conn.php");  
  
if(!empty($_GET['id'])){  
    $sql = "SELECT * FROM ly_micro_blog WHERE id = ".$_GET['id'];  
    $rc = mysql_fetch_array(mysql_query($sql));  
    mysql_query("UPDATE ly_micro_blog SET hits = hits + 1 WHERE id = ".$_GET['id']);  
} else {  
    echo "参数引入失败!";  
}  
?>  
  
DOCTYPE HTML>  
<html>  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
<title>php echo $rc['title'];?>|我的微博客title>  
head>  
  
<body>  
<a href="default.php">返回主页面a>  
<hr color="#00FFFF" size="5px"/>  
<h2>php echo $rc['title'];?>  
  <hr color="#006699" size="3px">  
h2>  
<li>php echo "日期:".$rc['date']."|浏览次数:".$rc['hits'];?>li>  
<p>php echo $rc['content'];?>p>  
body>  
html>  

 

转自http://blog.csdn.net/sunshinedabby/article/details/7848125

 

转载于:https://www.cnblogs.com/bestsamcn/p/4824286.html

你可能感兴趣的:(利用PHP/MYSQL实现的简易微型博客(转))