Php+access Article Management program code _php Tips

Source: Internet
Author: User
Copy Code code as follows:

<?php
Session_Start ();
//==========================
Author: Biyuan
Time: 2006.07
Contact: QQ6010707
//==========================
?>
<title> Bi-Original network php+access article management system </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<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;
}
</style>
<body>
<?php
//==================================
Connecting to a database
//==================================
@ $conn = new COM ("ADODB. Connection ");
$conn->open ("Driver={microsoft Access DRIVER (*.mdb)};" Dbq= ". Realpath ("Article.mdb"));
//==================================
Article Navigation
//==================================
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. "</a>";
$rs->movenext ();
}
echo "| <a href=\ "? admin=login\" > Backstage Management </a>\r\n ";
$rs->close ();
if (@$_session["articleadmin"] = = "By_php_article") {
echo "<br/> Management Options-> | <a href=\ "? admin=class\" > Classification Management </a> | <a href=\ "? admin=insert\" > Published articles </a> | <a href=\ "? admin=list\" > Articles List </a> | <a href=\ "? admin=logout\" > Exit login </a> ";
}
}
//==================================
Article List: article_list (article category 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> article title </td><td> article author </td><td> published time </td><td> browse Times </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. "</a></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 "<br/> This category does not exist or temporarily does not have any articles!";
}
$rs->close ();
}
//==================================
Article detail: Article_look (article 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> article Author:". $rs->fields[2]->value. " | Publication time: ". Date ("Y-m-d h:i:s", $rs->fields[3]->value). " | Browse Number: ". $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 (); \ > Return </a>" <a href=\ "javascript: print (); \ > Print </a> "<a href=\" javascript:close (); \ > Close </a> "</td>\r\n"
. "</tr>\r\n"
. "</table>\r\n"
. "<script language=\" javascript\ ">document.title + +"-". $rs->fields[1]->value. "\"; </script>\r\n ";
}
else {
echo "<br/> The article does not exist or has been deleted by the administrator!";
}
$rs->close ();
}
//==================================
Background: Classification Management
//==================================
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 "Category: <input type=\" text\ "value=\". $rs->fields[1]->value. "\" name=\ "Class_". $rs->fields[0]->value. "\"/> Number: <input type=\ "text\" value=\ "". $rs->fields[2]->value. "\" name=\ "Class_cid_". $rs->fields[0]->value. "\"/> <input type=\ "button\" value=\ "Modify \" onclick=\ "frm.action=" "admin=class&class=edit&id=". $rs->fields[0]->value. "'; submit (); \"/> <input type=\ "button\" value=\ "delete \" onclick=\ "frm.action="? Admin=class&class=del&id =" . $rs->fields[0]->value. "'; submit (); \"/><br/>\r\n ";
$rs->movenext ();
}
echo "Category: <input type=\" text\ "name=\" class_name\ "/> Number: <input type=\" text\ "name=\" class_cid\ "/> < Input type=\ "button\" value=\ "Increase \" onclick=\ "frm.action= '" Admin=class&class=add '; submit (); \ "/> <input Type=\ "button\" value=\ "idle \ Disabled/>\r\n"
. "</form>\r\n";
Add a Category
if (@$_get["class"] = = "Add") {
if (@$_post["class_name"] = = "" | | @$_post["class_cid"] = = "") {
echo "<br/> fill incomplete!";
echo "<script language=\" javascript\ ">settimeout (\" History.back (); \);</script> ";
Exit ();
}
else {
@ $sql = "Insert into List (by_list,by_cid) Values ('"). $_post["Class_name"]. "' , '" . $_post["Class_cid"]. "')";
$conn->execute ($sql);
echo "<br/> Add success!";
echo "<script language=\" javascript\ ">settimeout (\ window.location.href= ' admin=class '; \"); </ Script> ";
}
}
Modify a Category
if (@$_get["class"] = = "edit") {
if (@$_post["Class_". $_get["id"]] = = "" | | @$_post["Class_cid_". $_get["id"]] = = "") {
echo "<br/> fill incomplete!";
echo "<script language=\" javascript\ ">settimeout (\" History.back (); \);</script> ";
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 "<br/> Modify success!";
echo "<script language=\" javascript\ ">settimeout (\ window.location.href= ' admin=class '; \"); </ Script> ";
}
}
Delete a category
if (@$_get["class"] = = "Del") {
@ $sql = "Delete from List Where id =". $_get["id"];
$conn->execute ($sql);
echo "<br/> Delete success!";
echo "<script language=\" javascript\ ">settimeout (\ window.location.href= ' admin=class '; \"); </script > ";
}
}
//==================================
Background: Post (HTML supported)
//==================================
function Admin_insert () {
Global $conn;
if (@$_get["innert"] = = "Add") {
if (@$_post["title"] = = "" | | @$_post["name"] = = "" | | @$_post["class"] = = "" | | @$_post["body"] = = "") {
echo "<br/> fill incomplete!";
echo "<script language=\" javascript\ ">settimeout (\" History.back (); \);</script> ";
Exit ();
}
else {
@ $body = $_post["Body"];
$body = Str_replace ("'", "" ", $body);
$body = Str_replace ("\ r \ n", "<br/>", $body);
@ $sql = "Insert into article (by_title,by_name,by_time,by_count,by_body,by_class) Values ('". $_post["title"]. "' , '" . $_post["Name"]. "' , #" . Date ("Y-m-d g:i:s"). "#, 0, '". $body. "' , '" . $_post["Class". "')";
$conn->execute ($sql);
echo "<br/> Add success!";
echo "<script language=\" javascript\ ">settimeout (\ window.location.href= ' Admin=insert '; \"); </ Script> ";
}
}
else {
echo "<div style=\" width:590px;text-align:left\ ">\r\n"
. "<form action=\"? admin=insert&innert=add\ "Method=\" post\ ">\r\n"
. "article title: <input type=\" text\ "name=\" title\ "/><br/>\r\n"
. "article Author: <input type=\" text\ "name=\" name\ "/><br/>\r\n"
. "Article Category: <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. "</option>\r\n";
$rs->movenext ();
}
echo "</select><br/>\r\n"
. "Article Body: <textarea cols=\" 70\ "rows=\" 14\ "name=\" body\ "></textarea><br/>\r\n"
. "<center><input type=\" submit\ "value=\" submit \/> <input type=\ "reset\" value=\ "Reset \"/></center >\r\n "
. "</form>\r\n"
. "</div>\r\n";
}
}
//==================================
Background: Articles List
//==================================
function Admin_list () {
Global $conn;
@ $sql = "Select Id,by_title,by_name,by_time,by_count,by_class from Article 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> article title </td><td> article classification <td> article author </td><td> publish time </td><td> browse times </ Td><td> Operation </td>\r\n "
. "</tr>\r\n";
while (! $rs->eof) {
@ $sql = "SELECT * from List Where by_cid =". $rs->fields[5]->value;
@ $crs = $conn->execute ($sql);
@ $cid = $crs->fields[1]->value;
echo "<tr bgcolor=\" #FFFFFF \ ">\r\n"
. "<td><a href=\"? artid= ". $rs->fields[0]->value. ">". $rs->fields[1]->value. "</a></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. "\" > Edit </a> | <a href=\ "? admin=list&list=del&id=". $rs->fields[0]->value. "\" > Delete </a></td>\r\n "
. "</tr>\r\n";
$crs->close ();
$rs->movenext ();
}
echo "</table>\r\n";
}
else {
echo "<br/> This category does not exist or temporarily does not have any articles!";
}
$rs->close ();
Modify an article
if (@$_get["list"] = = "edit") {
if (@$_get["edit"] = = "true") {
if (@$_post["title"] = = "" | | @$_post["name"] = = "" | | @$_post["class"] = = "" | | @$_post["body"] = = "") {
echo "<br/> fill incomplete!";
echo "<script language=\" javascript\ ">settimeout (\" History.back (); \);</script> ";
Exit ();
}
else {
@ $body = $_post["Body"];
$body = Str_replace ("'", "" ", $body);
$body = Str_replace ("\ r \ n", "<br/>", $body);
@ $sql = "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"];
$conn->execute ($sql);
echo "<br/> Modify success!";
echo "<script language=\" javascript\ ">settimeout (\ window.location.href= ' admin=list '; \"); </script > ";
}
}
else {
@ $sql = "SELECT * from Article Where id =". $_get["id"];
@ $rs = $conn->execute ($sql);
echo "<div style=\" width:590px;text-align:left\ ">\r\n"
. "<form action=\"? admin=list&list=edit&edit=true&id= ". $rs->fields[0]->value. "\" method=\ "post\" >\r\n "
. "article title: <input type=\" text\ "name=\" title\ "value=\" ". $rs->fields[1]->value. "\"/><br/>\r\n "
. Article Author: <input type=\ "text\" name=\ "name\" value=\ "". $rs->fields[2]->value. "\"/><br/>\r\n "
. "Browse Times: <input type=\" text\ "name=\" count\ "value=\" ". $rs->fields[4]->value. "\"/><br/>\r\n "
. "Article Category: <select name=\" class\ "id=\" class\ ">\r\n";
@ $sql = "SELECT * from List";
@ $crs = $conn->execute ($sql);
while (! $crs->eof) {
echo "<option value=\" ". $crs->fields[2]->value. ">". $crs->fields[1]->value. "</option>\r\n";
$crs->movenext ();
}
$crs->close ();
@ $body = $rs->fields[5]->value;
$body = Str_replace ("<br/>", "\ r \ n", $body);
echo "</select><br/>\r\n"
. "<script language=\" javascript\ ">\r\n"
. "document.getElementById (\" Class\ "). SelectedIndex =". $rs->fields[6]->value. "-1;\r\n"
. "</script>\r\n"
. "Article Body: <textarea cols=\" 70\ "rows=\" 14\ "name=\" body\ ">". $body. "</textarea><br/>\r\n"
. "<center><input type=\" submit\ "value=\" submit \/> <input type=\ "reset\" value=\ "Reset \"/></center >\r\n "
. "</form>\r\n"
. "</div>\r\n";
}
}
Delete an article
if (@$_get["list"] = = "Del") {
@ $sql = "Delete from Article Where id =". $_get["id"];
$conn->execute ($sql);
echo "<br/> Delete success!";
echo "<script language=\" javascript\ ">settimeout (\ window.location.href= ' admin=list '; \"); </script > ";
}
}
//==================================
Permission validation
//==================================
function Admin_session () {
if (@$_session["Articleadmin"]!= "By_php_article") {
echo "<br/> Please log in first!";
echo "<script language=\" javascript\ ">settimeout (\ window.location.href= ' admin=login '; \"); </ Script> ";
Exit ();
}
}
//==================================
Backstage Login
//==================================
function Admin_login () {
if (@$_session["articleadmin"] = = "By_php_article") {
echo "<script language=\" javascript\ ">window.location.href= ' admin=admin ';</script>";
}
else{
echo "<table border=\" 0\ "cellspacing=\" 1\ "cellpadding=\" 0\ "bgcolor=\" #cccccc \ ">\r\n"
. "<tr bgcolor=\" #F3F3F3 \ "align=\" Center\ ">\r\n"
. "<td><strong> Admin Login </strong></td>\r\n"
. "</tr>\r\n"
. "<tr bgcolor=\" #FFFFFF \ ">\r\n"
. "<form method=\" post\ "action=\"? Admin=check\ ">\r\n"
. "<td><input type=\" password\ name=\ "adminpass\"/><input type=\ "submit\" value=\ "OK \"/></td >\r\n "
. "</form>\r\n"
. "</tr>\r\n"
. "</table>\r\n";
}
}
//==================================
Login Verification
//==================================
function Admin_check () {
if (Trim ($_post["AdminPass"])!= "admin") {
echo "<br/> wrong password!";
echo "<script language=\" javascript\ ">settimeout (\" History.back (); \);</script> ";
}
else {
echo "<br/> Landing success!";
@$_session["articleadmin"] = "by_php_article";
echo "<script language=\" javascript\ ">settimeout (\ window.location.href= ' admin=admin '; \"); </ Script> ";
}
}
//==================================
URL parameter list
//==================================
function Page_Load () {
@ $classid = $_get["ClassID"];
if ($classid!= "") {
if (!is_numeric ($classid)) {
echo "<br/> wrong parameter!";
return false;
}
else {
Article_list ($CLASSID);
}
}
@ $artid = $_get["ArtID"];
if ($artid!= "") {
if (!is_numeric ($artid)) {
echo "<br/> wrong parameter!";
return false;
}
else {
Article_look ($artid);
}
}
@ $admin = $_get["admin"];
if ($admin = = "Login") {
Admin_login ();
}
if ($admin = = "Check") {
Admin_check ();
}
if ($admin = = "Admin") {
Admin_session ();
echo "<br/> Landing Success!" Please select the function menu to perform the operation. ";
}
if ($admin = = "Logout") {
Session_destroy ();
echo "<br/> has successfully exited!";
echo "<script language=\" javascript\ ">settimeout (\ window.location.href= ' admin=login '; \"); </ Script> ";
}
if ($admin = = "Class") {
Admin_session ();
Admin_class ();
}
if ($admin = = "Insert") {
Admin_session ();
Admin_insert ();
}
if ($admin = = "List") {
Admin_session ();
Admin_list ();
}
if ($classid = = "" && $artid = "" && $admin = = "") {
echo "<script language=\" javascript\ ">window.location.href= ' classid=1 ';</script>";
}
}
?>
<div style= "Width:100%;text-align:left;background: #cccccc; line-height:20px;" >
<br/><br/><br/> Article classification-> <?=article_menu ();? >
</div>
<?=page_load ();? >
<?php
$conn->close ();
?>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.