文章发布系统
后台管理系统-》
1, 文章管理列表
2, 文章发布程序
3, 文章修改程序
4, 文章删除程序
前台展示系统-》
1. 文章列表
2. 文章内容页
文章发布系统数据库-》
上面的代码写入connect.php文件中
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
l Config.php
<?php
define(‘HOST’,’127.0.0.1’);
define(‘USERNAME’,’root’);
define(‘PASSWORD’,’123’);
?>
l Connect.php
<?php
Require_once(‘config.php’);
//连库
If(!($con= musql_connect(HOST, USERNAME, PASSWORD))){
echomysql_error();
};
//选库
If(!(Mysql_select_db(‘info’))){
echomysql_error();
};
//字符集
If(Mysql_query(‘set names utf8’)){
echomysql_error();
};
?>
l article.add.php
<!DOCTYPEhtml>
<html>
<head>
<metacharset=”utf-8”/>
<title>文章添加前台界面</title>
<styletype=”text/css”>
body{
margin:0;
}
</style>
</head>
<body>
<td>
<p><ahref=”article.add.php”>发布文章</a></p>
<p><ahref=”article.manager.php”>管理文章</a></p>
<ahref=”article.add.php></a></td>”
<form id=”form1” name=”form1” method=”post”acticle.add.handle.php”>
<tablewidth=”779” border=”0” cellpadding=”8” cellacing=”1” >
<tr>
<tdcolspan=”2” align=”center”>发布文章</td>
</tr>
<tr>
<tdwidth=”119”>标题</td>
<tdwidth=”625”><label for=”title”></label>
<inputtype=”text” name=”title” id=”title”>
</td>
</tr>
<tr>
<td>简介</td>
<td>
<labelfor=”description”></label>
<textareaname=”description” id=”description”cols=”60” rows=”5”></textarea>
</td>
</tr>
<tr>
<td>内容</td>
<td><textareaname=”content” id=”content” cols=”60”rows=”15”></textarea></td>
</tr>
<tr>
<tdcolspan=”2” align=”right” ><input type=”submit” name=”button” id=”button”value=”提交” /></td>
</tr>
</table>
</form>
</body>
</html>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
l Article.add.handle.php
<?php
Require_once(‘../connect.php’);
//1把传递来的信息入库,2在入库之前对所有的信息进行校验
//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’];
$dataline= time();
$insertsql= “ Insert into article(title ,description, content, dateline) values(‘$title’,’$author’, ’$description’, ‘$content’ , ‘$dateline’)”;
echo $insertsql;//检查sql语句是否拼错
if(mydsql_query($insertsql)){
echo“<script>alert(‘文章发布成功’);window.location.href=’article.add.php’;</script>”;
}else{
echo“<script>alert(‘文章发布失败’);window.location.href=’article.add.php’;</script>”;
};
?>
l 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);//转化为数组,下面数据调用
?>
<!DOCTYPEhtml>
<html>
<head>
<metacharset = “utf-8”/>
<title>文章添加前台界面</title>
<styletype=”text/css”>
body{
margin:0;
}
</style>
</head>
<body>
<td>
<p><ahref=”article.add.php”>发布文章</a></p>
<p><ahref=”article.manager.php”>管理文章</a></p>
<ahref=”article.add.php></a></td>”
<form id=”form1” name=”form1” method=”post” acticle.modify.handle.php”>
<input type=”hidden” name=”id” value=”<?php echo $data[‘’id]?>”/>
<tablewidth=”779” border=”0” cellpadding=”8” cellacing=”1” >
<tr>
<tdcolspan=”2” align=”center”>修改文章</td>
</tr>
<tr>
<tdwidth=”119”>标题</td>
<tdwidth=”625”>
<labelfor=”title”></label>
<inputtype=”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>
<labelfor=”description”></label>
<textareaname=”description” id=”description”cols=”60” rows=”5”>
<?phpecho $data[‘description’]?></textarea>
</td>
</tr>
<tr>
<td>内容</td>
<td><textareaname=”content” id=”content” cols=”60”rows=”15”><?php echo $data[‘content’]?></textarea></td>
</tr>
<tr>
<tdcolspan=”2” align=”right” ><input type=”submit” name=”button” id=”button”value=”提交” /></td>
</tr>
</table>
</form>
</body>
</html>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
l article.modify.handle.php
<?php
Require_once(‘../connect.php’);
//1把传递来的信息入库,2在入库之前对所有的信息进行校验
//print_r($_POST);
If(!(isset($_POST[‘title’])&&(!empty($_POST[‘title’])))){
Echo“<script>alert(‘标题不能为空’);window.location.href=’article.add.php’;</script>”;
}
$id=$_GET[‘id’];
$title= $_POST[‘title’];
$author= $_POST[‘author’];
$description= $_POST[‘description’];
$content= $_POST[‘content’];
$dataline= time();
$updatesql= “update article set title = ‘$title’,author = ‘$author’, description = ‘$description’, content = ‘$content’,dateline = $dateline where id=$id”;
echo $insertsql;//检查sql语句是否拼错
if(mydsql_query($updatesql)){
echo“<script>alert(‘文章修改成功’);window.location.href=’article.manager.php’;</script>”;
}else{
echo“<script>alert(‘文章发布失败’);window.location.href=’article.manager.php’;</script>”;
};
?>
----------------------------------------------------------------------------------------------------------------------------------------------------------------
l article.del.handle.php
<?php
Require_once(‘../connect.php’);
$id= $_GET[‘id’];
$deletesql=”delete from article where id= $id”;
If(mysql_query($deletesql)){
echo“<script> alert(‘删除文章成功’);</script>”;
}else{
echo“<script> alert(‘删除文章失败’);</script>”;
}
?>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
l 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)){
While($row= mysql_fetch_assoc($query)){
$data[]= $row;
}
}else{
$data= array();
}
?>
<!DOCTYPEhtml>
<html>
<head>
<metacharset =”utf-8”/>
<title>文章管理界面</title>
</head>
<body>
<tablewidth=”100%” height =”520” border =”0” cellspadding=”0” cellspacing=”1” bgcolor=”#000”>
<tr>
<tdheight =”89” colspan=”2” bgcolor =”#ff9” ><strong>后台管理系统</strong></td>
</tr>
<tr>
<tdwidth =”156” height=”287” align=”left” valign=”top” bgcolor=”#ff9”><p><a href=”article.add.php”>发布文章</a></p>
<p><ahref=”article.manage.php”>管理文章</a></p>
</td>
<tdwidth=”873” valign=”top” bgcolor=”#fff”>
<tablewidth=”743” border=”0” cellpadding=”8” cellspacing=”1” bgcolor=”#000”>
<tr>
<tdcolspan=”3” align=”center” bgcolor=”#fff”>文章管理列表</td>
</tr>
<tr>
<tdwidth=”37” bgcolor=”#fff”>编号</td>
<tdwidth=”572” bgcolor=”#fff”>标题</td>
<tdwidth=”82” bgcolor=”#fff”>操作</td>
</tr>
<?php
If(!empty($data)){
foreach($data as $value){
?>
<tr>
<td bgcolor=”#fff”> <?php echo$value[‘id’]?><td>
<td bgcolor=”#fff”>$nbsp;<?php echo $value[‘title’]?></td>
<td bgcolor=”#fff”>
<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>
</body>
</html>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
l article.list.php
<?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;
}
}
//print_r($data);//打印检查
?>
<!DOCTYPE html>
<html>
<head>
<title>文章列表</title>
</head>
<body>
<divid=”content”>
<?php
If(empty($data)){
echo“当前没有文章,请管理员在后台添加文章”;
}else{
foreach($dataas $value){
?>
<divclass=”post”>
<h1class=”title”><?php echo $value[‘title’]?><span><?php echo$value[‘author’]?></span></h1>
<divclass=”entry” >
<p><?phpecho $value[‘description’]?></p>
</div>
<divclass=”meya”>
<pclass=”links”><a href=”article.show.php?id=<?php echo value[‘id’]?>” class=”more”>查看详情</a></p>
</div>
</div>
<?php
}
}
?>
</div>
<divid=”sidebar”>
<ul>
<liid=”search”>
<h2><bclass=”text1”>Search</b></h2>
<form method=”get” action =”article.search.php”>
<fieldset>
<inputtype=”text” id=”s” name=”key” value=””/>
<inputtype=”submit” id=”x” value=”Search”/>
</fieldset>
</form>
</li>
</ul>
</div>
</body>
</html>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
<?php
Require_once(‘connect.php’);
$id= $_GET[‘id’];//$id = intval($_GET[‘id’]);防止sql注入
$sql= “select * from article where id=$id”;
$query= mysql_query($sql);
If($query&&mysql_num_rows($query)){
$row= mysql_fetch_assoc($query);
}else{
echo“这篇文章不存在”;
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>文章列表</title>
</head>
<body>
<divid=”page”>
<div id=”content”>
<divclass=”post”>
<h1class=”title”><?php echo $row[‘title’]?><span><?php echo$row[‘author’]?><span>
</h1>
<divclass=”entry”><?php echo $row[‘content’]?>
</div>
</div>
</div>
</div>
</body>
</html>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
l article.search.php
<?php
Require_once(‘connect.php’);
$key= $_GET[‘key’];
$sql= “select * from article where title like ‘$key%’ order by dateline desc”;
$query= mysql_query($sql);
If($query&&mysql_num_rows($query)){
While($row= mysql_fetch_assoc($query)){
$data[]= $row;
}
}
?>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
l about.php
<?php
Require_once(‘connect.php’);
$sql= “select * from introduce”;
$query= mysql_query($sql);
If($query&&mysql_num_rows($query)){
$about= mysql_result($query, 0, ‘about’);
}
?>
<!DOCTYPEhtml>
<html>
<head></head>
<body>
<divid=”menu”>
<ul>
<liclass=”active”><a href=”article.list.php”>文章</a></li>
<li><a href=”about.php”>关于我们</a></li>
<li><ahref=”content.php”>联系我们</a></li>
</ul>
</div>
<divid=”content”>
<divclass=”post”>
<h1class=”title”>关于我们</h1>
<divclass=”entry”>
<?phpecho $about ?>
</div>
</div>
</div>
</body>
</html>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
l contact.php
<?php
Require_once(‘connect.php’);
$sql= “select * from introduce”;
$query= mysql_query($sql);
If($query&&mysql_num_rows($query)){
$contact= mysql_result($query, 0, ‘contact’);
}
?>
<!DOCTYPEhtml>
<html>
<head></head>
<body>
<divid=”menu”>
<ul>
<liclass=”active”><a href=”article.list.php”>文章</a></li>
<li><a href=”about.php”>关于我们</a></li>
<li><ahref=”content.php”>联系我们</a></li>
</ul>
</div>
<divid=”content”>
<divclass=”post”>
<h1class=”title”>关于我们</h1>
<divclass=”entry”>
<?phpecho $contact ?>
</div>
</div>
</div>
</body>
</html>