Copy codeThe Code is as follows: <? Php
Session_start ();
// ==================================
// Author: biyuan
// Time: 2006.07
// Contact: QQ6010707
// ==================================
?>
<Html>
<Head>
<Title> Biyuan 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>
</Head>
<Body>
<? Php
// ==========================================
// Connect to the 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 \ "> background 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 \ "> post </a> | <a href = \"? Admin = list \ "> Article list </a> | <a href = \"? Admin = logout \ "> log out </a> ";
}
}
// ==========================================
// Article list: article_list (document 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> title </td> <td> author </td> <td> posting time </td> <td> browsing 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 there are no articles at the moment! ";
}
$ Rs-> Close ();
}
// ==========================================
// Article details: 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> author :". $ rs-> Fields [2]-> value. "| posting time :". date ("Y-m-d H: I: s", $ rs-> Fields [3]-> value ). "| browsing times :". $ 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 (); \ "> back </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/> This 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. "\"/> No.: <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 \ "/> No: <input type = \ "text \" name = \ "class_cid \"/> <input type = \ "button \" value = \ "add \" 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/> not complete! ";
Echo "<script language = \" JavaScript \ "> setTimeout (\" history. back (); \ ", 2000); </script> ";
Exit ();
}
Else {
@ $ SQL = "Insert into List (by_list, by_cid) Values ('". $ _ POST ["class_name"]. "','". $ _ POST ["class_cid"]. "')";
$ Conn-> Execute ($ SQL );
Echo "<br/> added successfully! ";
Echo "<script language = \" JavaScript \ "> setTimeout (\" window. location. href = '? Admin = class'; \ ", 2000); </script> ";
}
}
// Modify a category
If (@ $ _ GET ["class"] = "edit "){
If (@ $ _ POST ["class _". $ _ GET ["id"] = "" | @ $ _ POST ["class_cid _". $ _ GET ["id"] = ""){
Echo "<br/> not complete! ";
Echo "<script language = \" JavaScript \ "> setTimeout (\" history. back (); \ ", 2000); </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/> modified successfully! ";
Echo "<script language = \" JavaScript \ "> setTimeout (\" window. location. href = '? Admin = class'; \ ", 2000); </script> ";
}
}
// Delete a category
If (@ $ _ GET ["class"] = "del "){
@ $ SQL = "Delete From List Where id =". $ _ GET ["id"];
$ Conn-> Execute ($ SQL );
Echo "<br/> deleted successfully! ";
Echo "<script language = \" JavaScript \ "> setTimeout (\" window. location. href = '? Admin = class'; \ ", 100); </script> ";
}
}
// ==========================================
// Background: post an article (HTML supported)
// ==========================================
Function admin_insert (){
Global $ conn;
If (@ $ _ GET ["innert"] = "add "){
If (@ $ _ POST ["title"] = "" | @ $ _ POST ["name"] = "" | @ $ _ POST ["class"] = "" | @ $ _ POST ["body"] = "") {
Echo "<br/> not complete! ";
Echo "<script language = \" JavaScript \ "> setTimeout (\" history. back (); \ ", 2000); </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/> added successfully! ";
Echo "<script language = \" JavaScript \ "> setTimeout (\" window. location. href = '? Admin = insert '; \ ", 2000); </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"
. "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: Article 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 Category <td> author </td> <td> posting time </td> <td> browsing Times </td>/ 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> <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 there are no articles at the moment! ";
}
$ Rs-> Close ();
// Modify an article
If (@ $ _ GET ["list"] = "edit "){
If (@ $ _ GET ["edit"] = "true "){
If (@ $ _ POST ["title"] = "" | @ $ _ POST ["name"] = "" | @ $ _ POST ["class"] = "" | @ $ _ POST ["body"] = "") {
Echo "<br/> not complete! ";
Echo "<script language = \" JavaScript \ "> setTimeout (\" history. back (); \ ", 2000); </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/> modified successfully! ";
Echo "<script language = \" JavaScript \ "> setTimeout (\" window. location. href = '? Admin = list'; \ ", 2000); </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"
. "Author: <input type = \" text \ "name = \" name \ "value = \"". $ rs-> fields [2]-> value. "\"/> <br/> \ r \ n"
. "Browsing 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/> deleted successfully! ";
Echo "<script language = \" JavaScript \ "> setTimeout (\" window. location. href = '? Admin = list'; \ ", 100); </script> ";
}
}
// ==========================================
// Permission Verification
// ==========================================
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 '; \ ", 2000); </script> ";
Exit ();
}
}
// ==========================================
// Background 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> Administrator Logon </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/> incorrect password! ";
Echo "<script language = \" JavaScript \ "> setTimeout (\" history. back (); \ ", 2000); </script> ";
}
Else {
Echo "<br/> login successful! ";
@ $ _ SESSION ["ARTICLEADMIN"] = "BY_PHP_ARTICLE ";
Echo "<script language = \" JavaScript \ "> setTimeout (\" window. location. href = '? Admin = admin'; \ ", 2000); </script> ";
}
}
// ==========================================
// URL parameter list
// ==========================================
Function page_load (){
@ $ Classid = $ _ GET ["classid"];
If ($ classid! = ""){
If (! Is_numeric ($ classid )){
Echo "<br/> Incorrect Parameter! ";
Return false;
}
Else {
Article_list ($ classid );
}
}
@ $ Artid = $ _ GET ["artid"];
If ($ artid! = ""){
If (! Is_numeric ($ artid )){
Echo "<br/> Incorrect 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/> login successful! Select the function menu for Operations .";
}
If ($ admin = "logout "){
Session_destroy ();
Echo "<br/> exited successfully! ";
Echo "<script language = \" JavaScript \ "> setTimeout (\" window. location. href = '? Admin = login '; \ ", 2000); </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/> document category-> <? = Article_menu ();?>
</Div>
<? = Page_load ();?>
<? Php
$ Conn-> Close ();
?>
</Body>
</Html>