PHP+ACCESS 文章管理程序代码
前端之家收集整理的这篇文章主要介绍了
PHP+ACCESS 文章管理程序代码,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<div class="codetitle"><a style="CURSOR: pointer" data="85462" class="copybut" id="copybut85462" onclick="doCopy('code85462')"> 代码如下:
<div class="codebody" id="code85462">
<?
PHP session_start();
//==========================
//作者:biyuan
//时间:2006.07
//联系:QQ6010707
//==========================
?>
碧原网络PHP+ACCESS文章管理系统 <style type="text/css">
body {
margin:0px;
text-align:center;
font-size:12px;
font-family:verdana;
}
td {
font-size:12px;
height:28px;
padding:4px;
font-family:verdana;
}
A:link,
A:visited,
A:active {
color: #005a17; text-decoration: none;
}
A:hover {
color: #ff5a00; text-decoration: underline;
}
<?
PHP //==================================
//连接
数据库 //==================================
@$conn = new com("ADODB.Connection");
$conn->Open("DRIVER={Microsoft Access Driver (
.mdb)}; DBQ=" . realpath("article.mdb"));
//==================================
//文章导航
//==================================
function article_menu(){
global $conn;
@$sql = "Select From List";
@$rs = $conn->Execute($
sql);
while(!$rs->Eof){
echo "|<a href=\"?classid=" . $rs->Fields[2]->value . "\">" . $rs->Fields[1]->value . "";
$rs->MoveNext();
}
echo "|<a href=\"?admin=login\">后台管理\r\n";
$rs->Close();
if(@$_SESSION["ARTICLEADMIN"] == "BY_PHP_ARTICLE"){
echo "
管理选项->|<a href=\"?admin=class\">分类管理|<a href=\"?admin=insert\">发表文章|<a href=\"?admin=list\">文章列表|<a href=\"?admin=logout\">退出登陆";
}
}
//==================================
//文章列表:article_list(文章分类ID)
//==================================
function article_list($str){
global $conn;
@$sql = "Select id,by_title,by_name,by_time,by_count From Article Where by_class = " . $str . " Order By id desc";
@$rs = $conn->Execute($sql);
if(!$rs->Eof){
echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"0\" bgcolor=\"#cccccc\">\r\n"
. " <tr bgcolor=\"#F3F3F3\" align=\"center\">\r\n"
. " <td>文章标题</td><td>文章作者</td><td>发表时间</td><td>浏览次数</td>\r\n"
. " </tr>\r\n";
while(!$rs->Eof){
echo " <tr bgcolor=\"#FFFFFF\">\r\n"
. " <td><a href=\"?artid=" . $rs->Fields[0]->value . "\">" . $rs->Fields[1]->value . "</td><td>" . $rs->Fields[2]->value . "</td><td>" . date("Y-m-d H:i:s",$rs->Fields[3]->value) . "</td><td>" . $rs->Fields[4]->value . "</td>\r\n"
. " </tr>\r\n";
$rs->MoveNext();
}
echo "</table>\r\n";
}
else {
echo "
该
分类不存在或暂时没有任何
文章!";
}
$rs->Close();
}
//==================================
//
文章详细:article_look(
文章ID)
//==================================
function article_look($str){
global $conn;
@$
sql = "Select
From Article Where id = " . $str;
@$rs = $conn->Execute($sql);
@$usql= "Update Article Set by_count = (by_count + 1) Where id = " . $str;
$conn->Execute($usql);
if(!$rs->Eof){
@$body = $rs->Fields[5]->value;
$body = str_replace("[url=file://%22,%22%22,$body/]\","",$body[/url]);
echo "<table border=\"0\" width=\"60%\" cellspacing=\"1\" cellpadding=\"0\" bgcolor=\"#cccccc\">\r\n"
. " <tr bgcolor=\"#F3F3F3\" align=\"center\">\r\n"
. " <td style=\"font-size:14px;font-weight:bold\">" . $rs->Fields[1]->value . "</td>\r\n"
. " </tr>\r\n"
. " <tr bgcolor=\"#F3F3F3\" align=\"center\">\r\n"
. " <td>文章作者:" . $rs->Fields[2]->value . "|发表时间:" . date("Y-m-d H:i:s",$rs->Fields[3]->value) . "|浏览次数:" . $rs->Fields[4]->value . "</td>\r\n"
. " </tr>\r\n"
. " <tr bgcolor=\"#FFFFFF\">\r\n"
. " <td>" . $body . "</td>\r\n"
. " </tr>\r\n"
. " <tr bgcolor=\"#F3F3F3\">\r\n"
. " <td align=\"right\">【 <a href=\"javascript:history.back();\">返 回 】【 <a href=\"javascript:print();\">打 印 】【 <a href=\"javascript:close();\">关 闭 】</td>\r\n"
. " </tr>\r\n"
. " </table>\r\n"
. " <script language=\"JavaScript\">document.title += \"--" . $rs->Fields[1]->value . "\";\r\n";
}
else {
echo "
该文章不存在或已被管理员删除!";
}
$rs->Close();
}
//==================================
//后台:分类管理
//==================================
function admin_class(){
global $conn;
@$sql = "Select From List";
@$rs = $conn->Execute($sql);
echo "<form action=\"\" method=\"post\" name=\"frm\">\r\n";
while(!$rs->Eof){
echo "类别:<input type=\"text\" value=\"" . $rs->Fields[1]->value . "\" name=\"class_" . $rs->Fields[0]->value . "\" />编号:<input type=\"text\" value=\"" . $rs->Fields[2]->value . "\" name=\"class
cid" . $rs->Fields[0]->value . "\" /><input type=\"button\" value=\"修改\" onclick=\"frm.action='?admin=class&class=edit&id=" . $rs->Fields[0]->value . "';submit();\" /><input type=\"button\" value=\"删除\" onclick=\"frm.action='?admin=class&class=del&id=" . $rs->Fields[0]->value . "';submit();\" />
\r\n";
$rs->MoveNext();
}
echo "类别:<input type=\"text\" name=\"class_name\" />编号:<input type=\"text\" name=\"class_cid\" /><input type=\"button\" value=\"增加\" onclick=\"frm.action='?admin=class&class=add';submit();\" /><input type=\"button\" value=\"闲置\" disabled />\r\n"
. "\r\n";
//增加一个类别
if(@$_GET["class"] == "add"){
if(@$_POST["class_name"] == "" || @$_POST["class_cid"] == ""){
echo "
填写不完整!";
echo "<script language=\"JavaScript\">setTimeout(\"history.back();\",2000);";
exit();
}
else {
@$sql = "Insert into List(by_list,by_cid) Values('" . $_POST["class_name"] . "','" . $_POST["class_cid"] . "')";
$conn->Execute($sql);
echo "
添加成功!";
echo "<script language=\"JavaScript\">setTimeout(\"window.location.href='?admin=class';\",2000);";
}
}
//修改一个类别
if(@$_GET["class"] == "edit"){
if(@$
POST["class" . $_GET["id"]] == "" || @$_POST["class
cid" . $_GET["id"]] == ""){
echo "
填写不完整!";
echo "<script language=\"JavaScript\">setTimeout(\"history.back();\",2000);";
exit();
}
else {
@$sql = "Update List Set by_list = '" . $
POST["class" . $_GET["id"]] . "',by_cid = '" . $_POST["class
cid" . $_GET["id"]] . "' Where id = " . $_GET["id"];
$conn->Execute($sql);
echo "
修改成功!";
echo "<script language=\"JavaScript\">setTimeout(\"window.location.href='?admin=class';\",2000);";
}
}
//删除一个类别
if(@$_GET["class"] == "del"){
@$sql = "Delete From List Where id = " . $_GET["id"];
$conn->Execute($sql);
echo "
删除成功!";
echo "<script language=\"JavaScript\">setTimeout(\"window.location.href='?admin=class';\",100);";
}
}
//==================================
//后台:发表文章(支持HTML)
//==================================
function admin_insert(){
global $conn;
if(@$_GET["innert"] == "add"){
if(@$_POST["title"] == "" || @$_POST["name"] == "" || @$_POST["class"] == "" || @$_POST["body"] == ""){
echo "
填写不完整!";
echo "<script language=\"JavaScript\">setTimeout(\"history.back();\",2000);";
exit();
}
else {
@$body = $_POST["body"];
$body = str_replace("'","''",$body);
$body = str_replace("\r\n","
",$body);
@$sql = "Insert into article(by_title,by_count,by_body,by_class) Values('" . $_POST["title"] . "','" . $_POST["name"] . "',#" . date("Y-m-d G:i:s") . "#,'" . $body . "','" . $_POST["class"] . "')";
$conn->Execute($sql);
echo "
添加成功!";
echo "<script language=\"JavaScript\">setTimeout(\"window.location.href='?admin=insert';\",2000);";
}
}
else {
echo "<div style=\"width:590px;text-align:left\">\r\n"
. "<form action=\"?admin=insert&innert=add\" method=\"post\">\r\n"
. "文章标题:<input type=\"text\" name=\"title\" />
\r\n"
. "文章作者:<input type=\"text\" name=\"name\" />
\r\n"
. "文章类别:<select name=\"class\">\r\n";
@$sql = "Select
From List";
@$rs = $conn->Execute($sql);
while(!$rs->Eof){
echo "<option value=\"" . $rs->Fields[2]->value . "\">" . $rs->Fields[1]->value . "\r\n";
$rs->MoveNext();
}
echo "
\r\n"
. "文章正文:<textarea cols=\"70\" rows=\"14\" name=\"body\">
\r\n"
. "<input type=\"submit\" value=\"提交\" /><input type=\"reset\" value=\"重置\" />\r\n"
. "\r\n"
. " echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"0\" bgcolor=\"#cccccc\">\r\n"
. " <tr bgcolor=\"#F3F3F3\" align=\"center\">\r\n"
. " <td>文章标题</td><td>文章分类<td>文章作者</td><td>发表时间</td><td>浏览次数</td><td>操作</td>\r\n"
. " </tr>\r\n";
@$sql = "Select From List Where by_cid = " . $rs->Fields[5]->value;
. " <td><a href=\"?artid=" . $rs->Fields[0]->value . "\">" . $rs->Fields[1]->value . "</td><td>" . $cid . "</td><td>" . $rs->Fields[2]->value . "</td><td>" . $rs->Fields[3]->value . "</td><td>" . $rs->Fields[4]->value . "</td><td><a href=\"?admin=list&list=edit&id=" . $rs->Fields[0]->value . "\">编辑|<a href=\"?admin=list&list=del&id=" . $rs->Fields[0]->value . "\">删除</td>\r\n"
. " </tr>\r\n";
if(@$_POST["title"] == "" || @$_POST["name"] == "" || @$_POST["class"] == "" || @$_POST["body"] == ""){
= "Update article Set by_title = '" . $_POST["title"] . "',by_name = '" . $_POST["name"] . "',by_count = " . $_POST["count"] . ",by_body = '" . $body . "',by_class = '" . $_POST["class"] . "' Where id = " . $_GET["id"];
echo "<script language=\"JavaScript\">setTimeout(\"window.location.href='?admin=list';\",2000);";
echo "<option value=\"" . $crs->Fields[2]->value . "\">" . $crs->Fields[1]->value . "\r\n";
. "<script language=\"JavaScript\">\r\n"
. "document.getElementById(\"class\").selectedIndex = " . $rs->fields[6]->value . " - 1;\r\n"
. "\r\n"
. "
正文:<textarea cols=\"70\" rows=\"14\" name=\"body\">" . $body . "
. "
. "\r\n"
. "