1. Create Categories Admin Page
Mainly includes the following pages:
A. index.php, prepare various variable data. For display page use.
B. categories.html.php, showing categories.
C. form.html.php, which is used to edit or add author pages.
Page suburb fruit:
2. Main process of Categories page
2.1 Is logged in
if (! User_is_login ()) { include ': /login.html.php '; Exit (); }
2.2 Whether you have permission
if {!user_has_role (' content editor ') { $error = ' content Editor may access this page ... '; c5/>include '. /access.denied.html.php '; Exit (); }
2.3 Adding categories to catalogs
//Add Categories if(isset($_get[' Add '])) { include $_server[' Document_root ']. ' /php_mysql_web/includes/db.inc.php '; Try { $pageTitle= ' Add category '; $action= ' Addcategory '; $categoryText= ' '; $id= ' '; $button= ' Add category '; include' Form.html.php '; Exit(); } Catch(pdoexception$e) { $error= ' Error getting list of jokes to edit ... '.$e-GetMessage (); include $_server[' Document_root ']. ' /php_mysql_web/includes/error.html.php '; Exit(); } } //Add Categories if(isset($_get[' Addcategory ']) &&$_post[' Categorytext ']! = ') { include $_server[' Document_root ']. ' /php_mysql_web/includes/db.inc.php '; Try { $sql= ' INSERT into category ' (name) VALUES (: categorytext); '; $s=$pdo->prepare ($sql); $s->bindvalue (': Categorytext ',$_post[' Categorytext ']); $s-execute (); } Catch(pdoexception$e) { $error= ' Error adding category ... '.$e-GetMessage (); include $_server[' Document_root ']. ' /php_mysql_web/includes/error.html.php '; Exit(); } Header(' Location:. ')); Exit(); }
2.4 Edit Category Catalogue
//Edit Categories if(isset($_post[' Action ']) and$_post[' action '] = = ' Edit ') { include $_server[' Document_root ']. ' /php_mysql_web/includes/db.inc.php '; Try { $sql= ' SELECT name from category WHERE ID =: ID '; $s=$pdo->prepare ($sql); $s->bindvalue (': Id ',$_post[' ID ']); $s-execute (); $row=$s-fetch (); $pageTitle= ' Edit category '; $action= ' Editcategory '; $categoryText=$row[' Name ']; $id=$_post[' ID ']; $button= ' Update category '; include' Form.html.php '; Exit(); } Catch(pdoexception$e) { $error= ' Error getting list of category to edit ... '.$e-GetMessage (); include $_server[' Document_root ']. ' /php_mysql_web/includes/error.html.php '; Exit(); } } //Edit Categories if(isset($_get[' Editcategory ']) &&$_post[' Categorytext ']! = ') { include $_server[' Document_root ']. ' /php_mysql_web/includes/db.inc.php '; Try { $sql=UPDATE category SET name =: Name WHERE ID =: ID;‘; $s=$pdo->prepare ($sql); $s->bindvalue (': Name ',$_post[' Categorytext ']); $s->bindvalue (': Id ',$_post[' ID ']); $s-execute (); } Catch(pdoexception$e) { $error= ' Error updating categories ... '.$e-GetMessage (); include $_server[' Document_root ']. ' /php_mysql_web/includes/error.html.php '; Exit(); } Header(' Location:. ')); Exit(); }
2.5 Delete a category directory
if(isset($_post[' Action ']) and$_post[' action '] = = ' Delete ') { include $_server[' Document_root ']. ' /php_mysql_web/includes/db.inc.php '; //Delete jokecategory Entries Try { $sql= ' DELETE from jokecategory WHERE CategoryID =: Id '; $s=$pdo->prepare ($sql); $s->bindvalue (': Id ',$_post[' ID ']); $s-execute (); } Catch(pdoexception$e) { $error= ' Error deleting jokecategory ... '.$e-GetMessage (); include $_server[' Document_root ']. ' /php_mysql_web/includes/error.html.php '; Exit(); } //Delete category Entries Try { $sql= ' DELETE from category WHERE ID =: ID '; $s=$pdo->prepare ($sql); $s->bindvalue (': Id ',$_post[' ID ']); $s-execute (); } Catch(pdoexception$e) { $error= ' Error deleting category ... '.$e-GetMessage (); include $_server[' Document_root ']. ' /php_mysql_web/includes/error.html.php '; Exit(); } Header(' Location:. ')); Exit(); }
2.6 Show Category List
//Show all categories in database ... Try { include $_server[' Document_root ']. ' /php_mysql_web/includes/db.inc.php '; $QUERYSQL= "SELECT ID, name from category;"; $result=$pdo->query ($QUERYSQL); foreach($result as $row) { $categories[] =Array(' id ' = =$row[' ID '], ' name ' = =$row[' Name ']); } //if (count ($categories) > 0) { $sql= "Select COUNT (*) as RCT from category;"; $s=$pdo->prepare ($sql); $s-execute (); $row=$s-fetch (); $rowCount=$row[' RCT ']; include' Categories.html.php '; } } Catch(pdoexception$e) { $error= "Query category failed ...".$e-GetMessage (); include $_server[' Document_root ']. ' /php_mysql_web/includes/error.html.php '; Exit(); }
PHP and MySQL Web development from novice to expert, 8th Day-Create Categories Admin page