article.manage.php
<?php
require_once('connect.php');
$sql = "select * from article order by dateline desc";
$query = mysql_query($sql);
if($query&&mysql_num_rows($query)){
//将结果集的内容存放在$data[],向数组添加值
while($row =mysql_fetch_assoc($query)){
$data[] = $row;
}
}else{
$data = array();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
</style>
</head>
<body>
<table width="100%" height="520" border="0" cellpadding="8" cellspacing="1" bgcolor="#000000">
<tr>
<td height="89" colspan="2" bgcolor="#FFFF99"><strong>后台管理系统</strong></td>
</tr>
<tr>
<td width="156" height="287" align="left" valign="top" bgcolor="#FFFF99"><p><a href="article.add.php">发布文章</a></p>
<p><a href="article.manage.php">管理文章</a></p></td>
<td width="837" valign="top" bgcolor="#FFFFFF"><table width="743" border="0" cellpadding="8" cellspacing="1" bgcolor="#000000">
<tr>
<td colspan="3" align="center" bgcolor="#FFFFFF">文章管理列表</td>
</tr>
<tr>
<td width="37" bgcolor="#FFFFFF">编号</td>
<td width="572" bgcolor="#FFFFFF">标题</td>
<td width="82" bgcolor="#FFFFFF">操作</td>
</tr>
<?php
//数据输出,判断数组是否为空,使用foreach获取值
if(!empty($data)){
foreach($data as $value){
?>
<tr>
<td bgcolor="#FFFFFF"> <?php echo $value['id']?></td>
<td bgcolor="#FFFFFF"> <?php echo $value['title']?></td>
<td bgcolor="#FFFFFF"><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
}
}
?>
</table></td>
</tr>
<tr>
<td colspan="2" bgcolor="#FFFF99"><strong>版权所有</strong></td>
</tr>
</table>
</body>
</html>
article.del.handle.php
<?php
require_once('connect.php');
$_GET['id'];
$id = $_GET['id'];
$deletesql = "delete from article where id=$id";
echo $deletesql;
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.modify.php
<?php
require_once('connect.php');
//读取旧信息
$id = $_GET['id'];
$query = mysql_query("select * from article where id=$id");
$data = mysql_fetch_assoc($query);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
</style>
</head>
<body>
<table width="100%" height="520" border="0" cellpadding="8" cellspacing="1" bgcolor="#000000">
<tr>
<td height="89" colspan="2" bgcolor="#FFFF99"><strong>后台管理系统</strong></td>
</tr>
<tr>
<td width="213" height="287" align="left" valign="top" bgcolor="#FFFF99"><p><a href="article.add.php">发布文章</a></p>
<p><a href="article.manage.php">管理文章</a></p> <a href="article.add.php"></a></td>
<td width="854" valign="top" bgcolor="#FFFFFF">
<form id="form1" name="form1" method="post" action="article.modify.handle.php">
<input type="hidden" name="id" value="<?php echo $data['id']?>" />
<table width="590" border="0" cellpadding="8" cellspacing="1">
<tr>
<td colspan="2" align="center">修改文章</td>
</tr>
<tr>
<td width="119">标题</td>
<td width="437"><label for="title"></label>
<input type="text" name="title" id="title" value="<?php echo $data['title']?>"/></td>
</tr>
<tr>
<td>作者</td>
<td><input type="text" name="author" id="author" value="<?php echo $data['author']?>"/></td>
</tr>
<tr>
<td>简介</td>
<td><label for="description"></label>
<textarea name="description" id="description" cols="60" rows="5"><?php echo $data['description']?></textarea></td>
</tr>
<tr>
<td>内容</td>
<td><textarea name="content" cols="60" rows="20" id="content"><?php echo $data['content']?></textarea></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" name="button" id="button" value="提交" /></td>
</tr>
</table>
</form></td>
</tr>
<tr>
<td colspan="2" bgcolor="#FFFF99"><strong>版权所有</strong></td>
</tr>
</table>
</body>
</html>
article.modify.handle.php
<?php
require_once('connect.php');
//获取表单的数据$_POST--通过表单传递过来的值
$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";
if(mysql_query($updatesql)){
echo "<script>alert('修改文章成功');window.location.href='article.manage.php';</script>";
}else{
echo "<script>alert('修改文章失败');window.location.href='article.manage.php';</script>";
}
?>