Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6c79c32

Browse files
案例blog,编辑文章功能
1 parent 041fab4 commit 6c79c32

File tree

6 files changed

+275
-226
lines changed

6 files changed

+275
-226
lines changed

‎.idea/workspace.xml‎

Lines changed: 198 additions & 212 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎php-mysql/blog/controller/update_blog.php‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,23 @@
55
* Date: 2016年11月7日
66
* Time: 18:25
77
*/
8-
//编辑文章
8+
//编辑文章
9+
require '../class/conn.php';
10+
11+
$sys_conn = new ConnDB();
12+
$conn = $sys_conn->GetConn();
13+
mysqli_query($conn,"set names 'utf8' ");
14+
$blog_id= $_POST['id'];
15+
$blog_title = $_POST['blog_title'];
16+
$blog_tag = $_POST['blog_tag'];
17+
$blog_content = $_POST['blog_content'];
18+
echo $blog_content.'<br>';
19+
20+
echo 'id:'.$blog_id;
21+
$sql1 = mysqli_query($conn,"update tb_blog set title='$blog_title',tag='$blog_tag',content='$blog_content' where id='$blog_id'");
22+
if($sql1){
23+
$sys_conn->CloseConn();
24+
echo "<script>alert('更新文章内容成功!');//window.location.href= '/php-mysql/blog/dashboard.php';</script>";
25+
}else{
26+
echo "<script>alert('保存信息失败!')</script>";
27+
}

‎php-mysql/blog/css/style.css‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,15 @@ li.blog-item {
5454
background: #f5f5f5;
5555
text-align: center;
5656
line-height: 50px;
57+
}
58+
.btn{
59+
padding: 4px 10px;
60+
margin-right: 5px;
61+
}
62+
@media (min-width: 768px){
63+
.form-horizontal .control-label {
64+
padding-top: 0px;
65+
margin-bottom: 0;
66+
text-align: right;
67+
}
5768
}

‎php-mysql/blog/dashboard.php‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
<link rel="stylesheet" href="css/style.css">
1919
<script src="js/jquery.js"></script>
2020
<script src="js/bootstrap.min.js"></script>
21+
<style>
22+
.item-manage{
23+
margin-bottom: 5px;
24+
}
25+
</style>
2126
</head>
2227
<body>
2328
<?php include 'header.php'; ?>
@@ -68,14 +73,17 @@
6873
$item = $home_data->show_blog_list();
6974
$num = count($item);
7075
for($i=0;$i<$num;$i++){
76+
$id = $i+1;
7177
$item_content = '';
7278
if(strlen($item[$i]['content'])>160){
7379
$item_content = mb_substr($item[$i]['content'],0,160). '...';
7480
} else{ $item_content = $item[$i]['content'];}
7581

76-
echo "<li ><div class='item-title'><h4>".$item[$i]['title']."</h4></div>"
82+
echo "<li class='blog-item'><div class='item-title'><h4><a href='/php-mysql/blog/article.php?id=$id' target='_blank'>".$item[$i]['title']."</a></h4></div>"
7783
."<div class='item-tag'><a href='#' class='btn btn-info'>".$item[$i]['tag']."</a></div >"
78-
."<div class='item-content'>".$item_content."</div ></li >" ;
84+
."<div class='item-content'>".$item_content."</div >"
85+
."<div class='item-manage'><a href='/php-mysql/blog/edit.php?id=$id' class='btn btn-info' target='_blank'>编辑</a><a href='/php-mysql/blog/delete.php?id=$id' class='btn btn-warning' target='_blank'>删除</a></div>"
86+
."</li >" ;
7987
}
8088
?>
8189
</ul>

‎php-mysql/blog/edit.php‎

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,27 @@
22
/**
33
* Created by PhpStorm.
44
* User: zq199
5-
* Date: 2016/10/31
6-
* Time: 23:02
5+
* Date: 2016/11/8
6+
* Time: 23:29
77
*/
88
//内容编辑页面
99
require 'class/system.php';
10-
require '';
11-
//主页
10+
11+
$url = $_SERVER["QUERY_STRING"];
12+
$url_parse = explode('=', $url);
13+
$id = $url_parse[1];
14+
//$id = $_POST['id'];
15+
function get_blog_list($id){
16+
$sys_conn1 = new ConnDB();
17+
$conn = $sys_conn1->GetConn();
18+
mysqli_query($conn,"set names 'utf8' ");
19+
20+
$sql = mysqli_query($conn," select *from tb_blog where id='$id'");
21+
$info = mysqli_fetch_array($sql);
22+
23+
return $info;
24+
}
25+
$item = get_blog_list($id);
1226
?>
1327
<!DOCTYPE html>
1428
<html lang="en">
@@ -17,6 +31,8 @@
1731
<title><?php echo SITE_NAME ?>| 编辑文章</title>
1832
<link rel="stylesheet" href="css/bootstrap.min.css">
1933
<link rel="stylesheet" href="css/style.css">
34+
<script src="js/jquery.js"></script>
35+
<script src="js/bootstrap.min.js"></script>
2036
<style>
2137
.control-label{
2238
line-height: 34px;
@@ -27,24 +43,30 @@
2743
<body>
2844
<?php include 'header.php'; ?>
2945
<div class="content col-md-10 col-md-offset-1">
30-
<div class="add-blog">
31-
<div class="breadcrumb"><a href="index.php" style="margin-right:5px ">blog</a>\<span style="margin-left: 5px">新建</span></div>
32-
<form class="form-group form-horizontal" action="controller/add_new.php" method="post" name="update-blog-form">
46+
<div class="add-blog col-sm-12">
47+
<div class="breadcrumb"><a href="index.php" style="margin-right:5px ">文章</a>\<span style="margin-left: 5px"><?php echo $id ?></span></div>
48+
<form class="form-group form-horizontal" action="controller/update_blog.php" method="post" name="edit-blog-form">
49+
<div class="blog_id form-group col-sm-12 clearfix">
50+
<label for="blog_id" class="col-sm-1 control-label" style="text-align: left">id:</label>
51+
<div class="col-sm-11">
52+
<input type="text" class="form-control" name="id" id="blog_id" placeholder="<?php echo $item['id'] ?>" />
53+
</div>
54+
</div>
3355
<div class="blog_title form-group col-sm-12 clearfix">
3456
<label for="blog_title" class="col-sm-1 control-label" style="text-align: left">标题:</label>
3557
<div class="col-sm-11">
36-
<input type="text" name="blog_title" id="blog_title" placeholder="请填写标题" />
58+
<input type="text" class="form-control" name="blog_title" id="blog_title" placeholder="<?phpecho$item['title'] ?>" />
3759
</div>
3860
</div>
3961
<div class="blog_title form-group col-sm-12 clearfix">
4062
<label for="blog_tag" class="col-sm-1 control-label" style="text-align: left">标签:</label>
4163
<div class="col-sm-11">
42-
<input type="text" class="form-control" name="blog_tag" id="blog_tag" placeholder="请填写分类或者标签,多个请用英文逗号','分割开" />
64+
<input type="text" class="form-control" name="blog_tag" id="blog_tag" placeholder="<?phpecho$item['tag'] ?>" />
4365
</div>
4466
</div>
4567
<div class="form-group col-sm-12 clearfix">
4668
<label for="blog_content" class="control-label" style="padding: 0 15px">内容:</label>
47-
<textarea class="form-control" rows="6" id="blog_content" name="blog_content" style=""></textarea>
69+
<textarea class="form-control" rows="6" id="blog_content" name="blog_content" style=""><?phpecho$item['content'] ?></textarea>
4870
</div>
4971
<div class="form-group clearfix">
5072
<div class="col-sm-12">
@@ -57,3 +79,6 @@
5779
<?php include 'footer.php'; ?>
5880
</body>
5981
</html>
82+
83+
84+

‎php-mysql/blog/footer.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
?>
1010
<!--网站footer-->
1111
<div class="footer col-md-12">
12-
Copyright &copy; 2016 <a href="/index.php" target="_blank" ><?php echo SITE_OWNER ?><?php $_COOKIE['site_name'] ?></a>
12+
Copyright &copy; 2016 <a href="/php-mysql/blog/index.php" target="_blank" ><?php echo SITE_OWNER ?><?php $_COOKIE['site_name'] ?></a>
1313
</div>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /