简易 文章发布系统——后台管理系统

来自于慕课网的学习
       这里建立一个简易的文章发布系统——后台管理系统,功能包括 文章的发表、查看文章列表,其中还提供对文章的删除和修改功能。
       首先使用mysql建立数据库 info,在info数据库中建立一张 article 表:

       文章发布系统的目录结构如下:

       为实现操作数据库的功能,需要做php连接数据库等操作,所以先封装这些操作,当需要操作数据库时,将文件引入即可。
      数据库的配置 config.php
  1. <?php  
  2.     //防止乱码  
  3.     header("Content-type:text/html;charset=utf-8");  
  4.     define('HOST','127.0.0.1');  
  5.     define('USERNAME','root');  
  6.     define('PASSWORD','root');  
  7. ?>  
<?php
	//防止乱码
	header("Content-type:text/html;charset=utf-8");
	define('HOST','127.0.0.1');
	define('USERNAME','root');
	define('PASSWORD','root');
?>
       连接数据库等操作 connect.php
  1. <?php  
  2.     require_once('config.php');  
  3.   
  4.     //文件头部设置  
  5.     error_reporting(E_ALL &~E_NOTICE &~E_DEPRECATED);  
  6.   
  7.     //1.连库  
  8.     if(!($con = mysql_connect(HOST,USERNAME,PASSWORD))) {  
  9.         echo mysql_error();  
  10.     }  
  11.     //2.选库  
  12.     if(!mysql_select_db("info")) {  
  13.         echo mysql_error();  
  14.     }  
  15.     //3.字符集  
  16.     if(!mysql_query("set names utf8")) {  
  17.         echo mysql_error();  
  18.     }  
  19. ?>  
<?php
	require_once('config.php');

	//文件头部设置
	error_reporting(E_ALL &~E_NOTICE &~E_DEPRECATED);

	//1.连库
	if(!($con = mysql_connect(HOST,USERNAME,PASSWORD))) {
		echo mysql_error();
	}
	//2.选库
	if(!mysql_select_db("info")) {
		echo mysql_error();
	}
	//3.字符集
	if(!mysql_query("set names utf8")) {
		echo mysql_error();
	}
?>


        下面首先实现发布文章的功能,使用到 bootstrap 建立一个简单的页面 article.add.php ,效果如下:

      myCss/style.css
  1. body {  
  2.     font-family:'Hiragino Sans GB','Microsoft Yahei',"WenQuanYi Micro Hei",SimSun,Tahoma,Arial,Helvetica,STHeiti;  
  3.   
  4.     /* background-color: #BDC3C7; */  
  5. }  
  6. textarea {  
  7.     resize: none;  
  8. }  
  9.   
  10. .title {  
  11.     padding-left30px;  
  12. }  
  13.   
  14. .body-container {  
  15.     /* border-radius: 8px; 
  16.      
  17.     padding: 20px; 
  18.     box-shadow: 0 0 1px 1px #DDD; */  
  19.   
  20.     margin-bottom80px;  
  21. }  
  22.   
  23. .copyright {  
  24.     background-color#BDC3C7;  
  25.     text-aligncenter;  
  26.     padding20px;  
  27.   
  28.     positionfixed;  
  29.     bottom: 0px;  
  30.     width100%;  
  31. }  
body {
	font-family:'Hiragino Sans GB','Microsoft Yahei',"WenQuanYi Micro Hei",SimSun,Tahoma,Arial,Helvetica,STHeiti;

	/* background-color: #BDC3C7; */
}
textarea {
	resize: none;
}

.title {
	padding-left: 30px;
}

.body-container {
	/* border-radius: 8px;
	
	padding: 20px;
	box-shadow: 0 0 1px 1px #DDD; */

	margin-bottom: 80px;
}

.copyright {
	background-color: #BDC3C7;
	text-align: center;
	padding: 20px;

	position: fixed;
	bottom: 0px;
	width: 100%;
}
       article.add.php
  1. <!DOCTYPE html>  
  2. <html lang="en">  
  3. <head>  
  4.     <meta charset="UTF-8">  
  5.     <title>发布文章</title>  
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">  
  7.     <meta name="description" content="文章发布系统——后台管理系统">  
  8.     <meta name="author" content="DreamBoy">  
  9.     <link rel="stylesheet" href="../css/bootstrap.min.css">  
  10.     <link rel="stylesheet" href="../myCss/style.css">  
  11. </head>  
  12. <body>  
  13.     <div class="container">  
  14.         <div class="page-header ex-page-header">  
  15.             <h1 class="title">文章发布系统<small>  ——后台管理系统</small></h1>  
  16.         </div>  
  17.   
  18.         <div class="body-container">  
  19.             <div class="row">  
  20.                     <div class="col-md-2">  
  21.                         <div class="panel panel-default">  
  22.                             <div class="panel-heading">  
  23.                                 <span class="glyphicon glyphicon-th-list" aria-hidden="true"></span>  
  24.                             </div>  
  25.                               
  26.                                 <div class="list-group">  
  27.                                     <a href="article.add.php" class="list-group-item active">发布文章</a>  
  28.                                     <a href="article.manage.php" class="list-group-item">管理文章</a>  
  29.                                 </div>  
  30.                         </div>  
  31.                     </div>  
  32.   
  33.                     <div class="col-md-10">  
  34.                         <div class="panel panel-default">  
  35.                             <div class="panel-heading">  
  36.                                 <h4>发布文章</h4>  
  37.                             </div>  
  38.   
  39.                             <div class="panel-body">  
  40.                                 <form method="post" action="article.add.handle.php" class="form-horizontal">  
  41.                                     <div class="form-group">  
  42.                                         <label for="article-title" class="col-sm-2 control-label">标题</label>  
  43.                                         <div class="col-sm-10">  
  44.                                             <input type="text" class="form-control" id="article-title" placeholder="Title" name="title">  
  45.                                         </div>  
  46.                                     </div>  
  47.   
  48.                                     <div class="form-group">  
  49.                                         <label for="article-author" class="col-sm-2 control-label">作者</label>  
  50.                                         <div class="col-sm-10">  
  51.                                             <input type="text" class="form-control" id="article-author" placeholder="Author" name="author">  
  52.                                         </div>  
  53.                                     </div>  
  54.   
  55.                                     <div class="form-group">  
  56.                                         <label for="article-des" class="col-sm-2 control-label">简介</label>  
  57.                                         <div class="col-sm-10">  
  58.                                             <textarea name="description" id="article-des" cols="30" rows="5" class="form-control"></textarea>  
  59.                                         </div>  
  60.                                     </div>  
  61.   
  62.                                     <div class="form-group">  
  63.                                         <label for="article-content" class="col-sm-2 control-label">内容</label>  
  64.                                         <div class="col-sm-10">  
  65.                                             <textarea name="content" id="article-content" cols="30" rows="15" class="form-control"></textarea>  
  66.                                         </div>  
  67.                                     </div>  
  68.   
  69.                                     <div class="form-group">  
  70.                                         <div class="col-sm-offset-2 col-sm-10">  
  71.                                             <button type="submit" class="btn btn-default">提交</button>  
  72.                                         </div>  
  73.                                     </div>  
  74.                                 </form>  
  75.                             </div>  
  76.                         </div>  
  77.                     </div>  
  78.                 </div>  
  79.             </div>  
  80.         </div>  
  81.     </div>  
  82.   
  83.     <footer class="copyright">  
  84.         Copyright &copyright; 1995-2016, DreamBoy.NET, All Rights Reserved  
  85.     </footer>  
  86. </body>  
  87. </html>  
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>发布文章</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="文章发布系统——后台管理系统">
    <meta name="author" content="DreamBoy">
	<link rel="stylesheet" href="../css/bootstrap.min.css">
	<link rel="stylesheet" href="../myCss/style.css">
</head>
<body>
	<div class="container">
		<div class="page-header ex-page-header">
			<h1 class="title">文章发布系统<small>  ——后台管理系统</small></h1>
		</div>

		<div class="body-container">
			<div class="row">
					<div class="col-md-2">
						<div class="panel panel-default">
							<div class="panel-heading">
								<span class="glyphicon glyphicon-th-list" aria-hidden="true"></span>
							</div>
							
								<div class="list-group">
									<a href="article.add.php" class="list-group-item active">发布文章</a>
									<a href="article.manage.php" class="list-group-item">管理文章</a>
								</div>
						</div>
					</div>

					<div class="col-md-10">
						<div class="panel panel-default">
							<div class="panel-heading">
								<h4>发布文章</h4>
							</div>

							<div class="panel-body">
								<form method="post" action="article.add.handle.php" class="form-horizontal">
									<div class="form-group">
										<label for="article-title" class="col-sm-2 control-label">标题</label>
										<div class="col-sm-10">
											<input type="text" class="form-control" id="article-title" placeholder="Title" name="title">
										</div>
									</div>

									<div class="form-group">
										<label for="article-author" class="col-sm-2 control-label">作者</label>
										<div class="col-sm-10">
											<input type="text" class="form-control" id="article-author" placeholder="Author" name="author">
										</div>
									</div>

									<div class="form-group">
										<label for="article-des" class="col-sm-2 control-label">简介</label>
										<div class="col-sm-10">
											<textarea name="description" id="article-des" cols="30" rows="5" class="form-control"></textarea>
										</div>
									</div>

									<div class="form-group">
										<label for="article-content" class="col-sm-2 control-label">内容</label>
										<div class="col-sm-10">
											<textarea name="content" id="article-content" cols="30" rows="15" class="form-control"></textarea>
										</div>
									</div>

									<div class="form-group">
										<div class="col-sm-offset-2 col-sm-10">
											<button type="submit" class="btn btn-default">提交</button>
										</div>
									</div>
								</form>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<footer class="copyright">
		Copyright &copyright; 1995-2016, DreamBoy.NET, All Rights Reserved
	</footer>
</body>
</html>
       当文章填写完毕之后,需要提交文章信息(即提交表单),需要一个处理程序进行数据库的添加操作,对应的文件为 article.add.handle.php,添加文章信息,并返回信息给浏览器,显示发布文章的状态(成功或失败),并跳转至文章的管理页面(文章列表)article.manage.php。
       article.add.handle.php
  1. <?php  
  2.     require_once('../connect.php');  
  3.     //把传递过来的信息入库,在入库之前对所有的信息进行校验。  
  4.     //print_r($_POST);  
  5.   
  6.     if(!isset($_POST['title']) || empty($_POST['title'])) {  
  7.         echo "<script>alert('标题不能为空'); window.location.href='article.add.php'</script>";  
  8.     }  
  9.   
  10.     $title = $_POST['title'];  
  11.     $author = $_POST['author'];  
  12.     $description = $_POST['description'];  
  13.     $content = $_POST['content'];  
  14.     $dateline = time();  
  15.   
  16.     $insertsql = "insert into article(title,author,description,content,dateline) values('$title','$author','$description','$content',$dateline)";  
  17.     //echo $insertsql;  
  18.     if(mysql_query($insertsql)) {  
  19.         echo "<script>alert('发布文章成功'); window.location.href='article.manage.php'</script>";   
  20.     } else {  
  21.         echo "<script>alert('发布文章失败'); window.location.href='article.manage.php'</script>";  
  22.     }  
  23.   
  24.     mysql_close($con);  
  25. ?>  
<?php
	require_once('../connect.php');
	//把传递过来的信息入库,在入库之前对所有的信息进行校验。
	//print_r($_POST);

	if(!isset($_POST['title']) || empty($_POST['title'])) {
		echo "<script>alert('标题不能为空'); window.location.href='article.add.php'</script>";
	}

	$title = $_POST['title'];
	$author = $_POST['author'];
	$description = $_POST['description'];
	$content = $_POST['content'];
	$dateline = time();

	$insertsql = "insert into article(title,author,description,content,dateline) values('$title','$author','$description','$content',$dateline)";
	//echo $insertsql;
	if(mysql_query($insertsql)) {
		echo "<script>alert('发布文章成功'); window.location.href='article.manage.php'</script>";	
	} else {
		echo "<script>alert('发布文章失败'); window.location.href='article.manage.php'</script>";
	}

	mysql_close($con);
?>

      article.manage.php 界面如下:


       为了处理文章的删除和修改操作,需要建立对应的php处理文件:article.del.handle.php、article.modify.handle.php。同时还有需要文章信息的界面 article.modify.handle.php。
       article.manage.php (需要对数据库进行查找,得到所有文章信息)
  1. <?php  
  2.     require_once('../connect.php');  
  3.     $sql = "select * from article order by dateline desc";  
  4.     $query = mysql_query($sql);  
  5.     if($query && mysql_num_rows($query)) {  
  6.         while($row = mysql_fetch_assoc($query)) {  
  7.             $data[] = $row;  
  8.         }  
  9.     } else {  
  10.         $data = array();  
  11.     }  
  12. ?>  
  13. <!DOCTYPE html>  
  14. <html lang="en">  
  15. <head>  
  16.     <meta charset="UTF-8">  
  17.     <title>管理文章</title>  
  18.     <meta name="viewport" content="width=device-width, initial-scale=1.0">  
  19.     <meta name="description" content="文章发布系统——后台管理系统">  
  20.     <meta name="author" content="DreamBoy">  
  21.     <link rel="stylesheet" href="../css/bootstrap.min.css">  
  22.     <link rel="stylesheet" href="../myCss/style.css">  
  23. </head>  
  24. <body>  
  25.     <div class="container">  
  26.         <div class="page-header ex-page-header">  
  27.             <h1 class="title">文章发布系统<small>  ——后台管理系统</small></h1>  
  28.         </div>  
  29.   
  30.         <div class="body-container">  
  31.             <div class="row">  
  32.                     <div class="col-md-2">  
  33.                         <div class="panel panel-default">  
  34.                             <div class="panel-heading">  
  35.                                 <span class="glyphicon glyphicon-th-list" aria-hidden="true"></span>  
  36.                             </div>  
  37.                               
  38.                                 <div class="list-group">  
  39.                                     <a href="article.add.php" class="list-group-item">发布文章</a>  
  40.                                     <a href="article.manage.php" class="list-group-item active">管理文章</a>  
  41.                                 </div>  
  42.                         </div>  
  43.                     </div>  
  44.   
  45.                     <div class="col-md-10">  
  46.                         <div class="panel panel-default">  
  47.                             <div class="panel-heading">  
  48.                                 <h4>文章管理列表</h4>  
  49.                             </div>  
  50.   
  51.                             <div class="panel-body">  
  52.                                 <table class="table table-hover">  
  53.                                     <tr>  
  54.                                         <th>编号</th>  
  55.                                         <th>标题</th>  
  56.                                         <th>操作</th>  
  57.                                     </tr>  
  58.   
  59.                                     <tbody>  
  60.                                         <?php  
  61.                                             if(!empty($data)) {  
  62.                                                 foreach ($data as $value) {  
  63.                                         ?>  
  64.                                                     <tr>  
  65.                                                         <td><?php echo $value['id'];?></td>  
  66.                                                         <td><?php echo $value['title'];?></td>  
  67.                                                         <td><a href="article.del.handle.php?id=<?php echo $value['id'];?>">删除</a>  
  68.                                                              <a href="article.modify.php?id=<?php echo $value['id'];?>">修改</a>  
  69.                                                         </td>  
  70.                                                     </tr>  
  71.                                         <?php  
  72.                                                 }  
  73.                                             }  
  74.                                         ?>  
  75.                                     </tbody>  
  76.                                 </table>  
  77.                             </div>  
  78.                         </div>  
  79.                     </div>  
  80.                 </div>  
  81.             </div>  
  82.         </div>  
  83.     </div>  
  84.   
  85.     <footer class="copyright">  
  86.         Copyright &copyright; 1995-2016, DreamBoy.NET, All Rights Reserved  
  87.     </footer>  
  88. </body>  
  89. </html>  
<?php
	require_once('../connect.php');
	$sql = "select * from article order by dateline desc";
	$query = mysql_query($sql);
	if($query && mysql_num_rows($query)) {
		while($row = mysql_fetch_assoc($query)) {
			$data[] = $row;
		}
	} else {
		$data = array();
	}
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>管理文章</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="文章发布系统——后台管理系统">
    <meta name="author" content="DreamBoy">
	<link rel="stylesheet" href="../css/bootstrap.min.css">
	<link rel="stylesheet" href="../myCss/style.css">
</head>
<body>
	<div class="container">
		<div class="page-header ex-page-header">
			<h1 class="title">文章发布系统<small>  ——后台管理系统</small></h1>
		</div>

		<div class="body-container">
			<div class="row">
					<div class="col-md-2">
						<div class="panel panel-default">
							<div class="panel-heading">
								<span class="glyphicon glyphicon-th-list" aria-hidden="true"></span>
							</div>
							
								<div class="list-group">
									<a href="article.add.php" class="list-group-item">发布文章</a>
									<a href="article.manage.php" class="list-group-item active">管理文章</a>
								</div>
						</div>
					</div>

					<div class="col-md-10">
						<div class="panel panel-default">
							<div class="panel-heading">
								<h4>文章管理列表</h4>
							</div>

							<div class="panel-body">
								<table class="table table-hover">
									<tr>
										<th>编号</th>
										<th>标题</th>
										<th>操作</th>
									</tr>

									<tbody>
										<?php
											if(!empty($data)) {
												foreach ($data as $value) {
										?>
													<tr>
														<td><?php echo $value['id'];?></td>
														<td><?php echo $value['title'];?></td>
														<td><a href="article.del.handle.php?id=<?php echo $value['id'];?>">删除</a>
															 <a href="article.modify.php?id=<?php echo $value['id'];?>">修改</a>
														</td>
													</tr>
										<?php
												}
											}
										?>
									</tbody>
								</table>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<footer class="copyright">
		Copyright &copyright; 1995-2016, DreamBoy.NET, All Rights Reserved
	</footer>
</body>
</html>
       点击“删除”时,将对对应文章进行删除操作,删除操作提交给article.del.handle.php文件进行处理。
       article.del.handle.php
  1. <?php  
  2.     require_once('../connect.php');  
  3.   
  4.     $id = intval($_GET['id']);  
  5.     $deletesql = "delete from article where id=$id";  
  6.     if(mysql_query($deletesql)) {  
  7.         echo "<script>alert('删除文章成功'); window.location.href='article.manage.php'</script>";  
  8.     } else {  
  9.         echo "<script>alert('删除文章失败'); window.location.href='article.manage.php'</script>";  
  10.     }  
  11. ?>  
<?php
	require_once('../connect.php');

	$id = intval($_GET['id']);
	$deletesql = "delete from article where id=$id";
	if(mysql_query($deletesql)) {
		echo "<script>alert('删除文章成功'); window.location.href='article.manage.php'</script>";
	} else {
		echo "<script>alert('删除文章失败'); window.location.href='article.manage.php'</script>";
	}
?>
       完成删除操作后(不论删除成功或删除失败),跳转到原来的文章管理界面article.manage.php。
       点击“修改”时,将传递对应文章的“id”到修改页面 article.modify.php。修改页面接收到文章id后,根据该id查询该文章的信息,将文章的信息显示在文本框中,供管理员修改。
       点击id为6的文章进行修改:

       跳转修改界面:

       article.modify.php
  1. <?php  
  2.     require_once('../connect.php');  
  3.     //读取旧信息  
  4.     $id = intval($_GET['id']);  
  5.     $query = mysql_query("select * from article where id=$id");  
  6.     $data = mysql_fetch_assoc($query);  
  7. ?>  
  8. <!DOCTYPE html>  
  9. <html lang="en">  
  10. <head>  
  11.     <meta charset="UTF-8">  
  12.     <title>修改文章</title>  
  13.     <meta name="viewport" content="width=device-width, initial-scale=1.0">  
  14.     <meta name="description" content="文章发布系统——后台管理系统">  
  15.     <meta name="author" content="DreamBoy">  
  16.     <link rel="stylesheet" href="../css/bootstrap.min.css">  
  17.     <link rel="stylesheet" href="../myCss/style.css">  
  18. </head>  
  19. <body>  
  20.     <div class="container">  
  21.         <div class="page-header ex-page-header">  
  22.             <h1 class="title">文章发布系统<small>  ——后台管理系统</small></h1>  
  23.         </div>  
  24.   
  25.         <div class="body-container">  
  26.             <div class="row">  
  27.                     <div class="col-md-2">  
  28.                         <div class="panel panel-default">  
  29.                             <div class="panel-heading">  
  30.                                 <span class="glyphicon glyphicon-th-list" aria-hidden="true"></span>  
  31.                             </div>  
  32.                               
  33.                                 <div class="list-group">  
  34.                                     <a href="article.add.php" class="list-group-item">发布文章</a>  
  35.                                     <a href="article.manage.php" class="list-group-item">管理文章</a>  
  36.                                 </div>  
  37.                         </div>  
  38.                     </div>  
  39.   
  40.                     <div class="col-md-10">  
  41.                         <div class="panel panel-default">  
  42.                             <div class="panel-heading">  
  43.                                 <h4>修改文章</h4>  
  44.                             </div>  
  45.   
  46.                             <div class="panel-body">  
  47.                                 <form method="post" action="article.modify.handle.php" class="form-horizontal">  
  48.                                     <input type="hidden" name="id" value="<?php echo $data['id'];?>">  
  49.   
  50.                                     <div class="form-group">  
  51.                                         <label for="article-title" class="col-sm-2 control-label">标题</label>  
  52.                                         <div class="col-sm-10">  
  53.                                             <input type="text" class="form-control" id="article-title" placeholder="Title" name="title" value="<?php echo $data['title'];?>">  
  54.                                         </div>  
  55.                                     </div>  
  56.   
  57.                                     <div class="form-group">  
  58.                                         <label for="article-author" class="col-sm-2 control-label">作者</label>  
  59.                                         <div class="col-sm-10">  
  60.                                             <input type="text" class="form-control" id="article-author" placeholder="Author" name="author" value="<?php echo $data['author'];?>">  
  61.                                         </div>  
  62.                                     </div>  
  63.   
  64.                                     <div class="form-group">  
  65.                                         <label for="article-des" class="col-sm-2 control-label">简介</label>  
  66.                                         <div class="col-sm-10">  
  67.                                             <textarea name="description" id="article-des" cols="30" rows="5" class="form-control"><?php echo $data['description'];?></textarea>  
  68.                                         </div>  
  69.                                     </div>  
  70.   
  71.                                     <div class="form-group">  
  72.                                         <label for="article-content" class="col-sm-2 control-label">内容</label>  
  73.                                         <div class="col-sm-10">  
  74.                                             <textarea name="content" id="article-content" cols="30" rows="15" class="form-control"><?php echo $data['content'];?></textarea>  
  75.                                         </div>  
  76.                                     </div>  
  77.   
  78.                                     <div class="form-group">  
  79.                                         <div class="col-sm-offset-2 col-sm-10">  
  80.                                             <button type="submit" class="btn btn-default">提交</button>  
  81.                                         </div>  
  82.                                     </div>  
  83.                                 </form>  
  84.                             </div>  
  85.                         </div>  
  86.                     </div>  
  87.                 </div>  
  88.             </div>  
  89.         </div>  
  90.     </div>  
  91.   
  92.     <footer class="copyright">  
  93.         Copyright &copyright; 1995-2016, DreamBoy.NET, All Rights Reserved  
  94.     </footer>  
  95. </body>  
  96. </html>  
<?php
	require_once('../connect.php');
	//读取旧信息
	$id = intval($_GET['id']);
	$query = mysql_query("select * from article where id=$id");
	$data = mysql_fetch_assoc($query);
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>修改文章</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="文章发布系统——后台管理系统">
    <meta name="author" content="DreamBoy">
	<link rel="stylesheet" href="../css/bootstrap.min.css">
	<link rel="stylesheet" href="../myCss/style.css">
</head>
<body>
	<div class="container">
		<div class="page-header ex-page-header">
			<h1 class="title">文章发布系统<small>  ——后台管理系统</small></h1>
		</div>

		<div class="body-container">
			<div class="row">
					<div class="col-md-2">
						<div class="panel panel-default">
							<div class="panel-heading">
								<span class="glyphicon glyphicon-th-list" aria-hidden="true"></span>
							</div>
							
								<div class="list-group">
									<a href="article.add.php" class="list-group-item">发布文章</a>
									<a href="article.manage.php" class="list-group-item">管理文章</a>
								</div>
						</div>
					</div>

					<div class="col-md-10">
						<div class="panel panel-default">
							<div class="panel-heading">
								<h4>修改文章</h4>
							</div>

							<div class="panel-body">
								<form method="post" action="article.modify.handle.php" class="form-horizontal">
									<input type="hidden" name="id" value="<?php echo $data['id'];?>">

									<div class="form-group">
										<label for="article-title" class="col-sm-2 control-label">标题</label>
										<div class="col-sm-10">
											<input type="text" class="form-control" id="article-title" placeholder="Title" name="title" value="<?php echo $data['title'];?>">
										</div>
									</div>

									<div class="form-group">
										<label for="article-author" class="col-sm-2 control-label">作者</label>
										<div class="col-sm-10">
											<input type="text" class="form-control" id="article-author" placeholder="Author" name="author" value="<?php echo $data['author'];?>">
										</div>
									</div>

									<div class="form-group">
										<label for="article-des" class="col-sm-2 control-label">简介</label>
										<div class="col-sm-10">
											<textarea name="description" id="article-des" cols="30" rows="5" class="form-control"><?php echo $data['description'];?></textarea>
										</div>
									</div>

									<div class="form-group">
										<label for="article-content" class="col-sm-2 control-label">内容</label>
										<div class="col-sm-10">
											<textarea name="content" id="article-content" cols="30" rows="15" class="form-control"><?php echo $data['content'];?></textarea>
										</div>
									</div>

									<div class="form-group">
										<div class="col-sm-offset-2 col-sm-10">
											<button type="submit" class="btn btn-default">提交</button>
										</div>
									</div>
								</form>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<footer class="copyright">
		Copyright &copyright; 1995-2016, DreamBoy.NET, All Rights Reserved
	</footer>
</body>
</html>
       提交修改请求到article.modify.handle.php进行文章的更新处理。

       article.modify.handle.PHP

  1. <?php  
  2.     require_once('../connect.php');  
  3.     //把传递过来的信息入库,在入库之前对所有的信息进行校验。  
  4.     //print_r($_POST);  
  5.   
  6.     if(!isset($_POST['title']) || empty($_POST['title'])) {  
  7.         echo "<script>alert('标题不能为空'); window.history.go(-1);</script>";  
  8.         mysql_close($con);  
  9.         exit;  
  10.     }  
  11.   
  12.     $id = $_POST['id'];  
  13.     $title = $_POST['title'];  
  14.     $author = $_POST['author'];  
  15.     $description = $_POST['description'];  
  16.     $content = $_POST['content'];  
  17.     $dateline = time();  
  18.   
  19.     $updatesql = "update article set title = '$title',author = '$author',description = '$description',content = '$content',dateline=$dateline where id=$id";  
  20.     //echo $updatesql;  
  21.       
  22.     if(mysql_query($updatesql) && mysql_affected_rows($con)) {  
  23.         echo "<script>alert('修改文章成功'); window.location.href='article.manage.php'</script>";   
  24.     } else {  
  25.         echo "<script>alert('修改文章失败'); window.location.href='article.manage.php'</script>";  
  26.     }  
  27.   
  28.     mysql_close($con);  
  29. ?>  
<?php
	require_once('../connect.php');
	//把传递过来的信息入库,在入库之前对所有的信息进行校验。
	//print_r($_POST);

	if(!isset($_POST['title']) || empty($_POST['title'])) {
		echo "<script>alert('标题不能为空'); window.history.go(-1);</script>";
		mysql_close($con);
		exit;
	}

	$id = $_POST['id'];
	$title = $_POST['title'];
	$author = $_POST['author'];
	$description = $_POST['description'];
	$content = $_POST['content'];
	$dateline = time();

	$updatesql = "update article set title = '$title',author = '$author',description = '$description',content = '$content',dateline=$dateline where id=$id";
	//echo $updatesql;
	
	if(mysql_query($updatesql) && mysql_affected_rows($con)) {
		echo "<script>alert('修改文章成功'); window.location.href='article.manage.php'</script>";	
	} else {
		echo "<script>alert('修改文章失败'); window.location.href='article.manage.php'</script>";
	}

	mysql_close($con);
?>

       点击提交“修改”后,修改成功:


        完成修改操作后(不论修改成功或修改失败),跳转到原来的文章管理界面article.manage.php。


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值