Faq system


Okay first were going to make a table in our mysql database called faq_system
Please insert this SQL query into your database...

SQL query:
PHP Code
  1. CREATE TABLE `faq_system` (
  2. `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  3. `general` TEXT NOT NULL ,
  4. `staff` TEXT NOT NULL ,
  5. `bugs` TEXT NOT NULL ,
  6. `tos` TEXT NOT NULL ,
  7. `last_by` VARCHAR( 25 ) NOT NULL ,
  8. `last_update` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
  9. ) ENGINE = MYISAM ;


Okay the table consists of 7 columns. These will be used i the faq system. Please use the following SQL query for this table...
PHP Code
  1. INSERT INTO `faq_system` (
  2. `id` ,
  3. `general` ,
  4. `staff` ,
  5. `bugs` ,
  6. `tos` ,
  7. `last_by` ,
  8. `last_update`
  9. )
  10. VALUES (
  11. NULL , 'None', 'None', 'None', 'None', 'No one', '0000-00-00 00:00:00'
  12. );

That'll basically post our current faq into the database. Dont worry you will get your chance to edit this later.

Now to use the table to make our first page. We will call this page file_faq.php
Feel free to call it whatever you wish. The following is the code we will use in file_faq.php

file_faq.php:
PHP Code
  1. <?
  2. session_start();
  3. //OKAY I HAVNT USED YOUR LOTS USER SYSTEM BEFORE SO IM JUST GOING TO STICK TO WHATS ITS THE CONFIG AND USE HELP FROM THAT. HEHE HOPE YOU CAN UNDERSTAND ME :P
  4. require_once "config.php"; //FOR SECURITY TERMS I WILL USE REQUIRE ONCE INSTEAD OF INCLUDE
  5.  
  6. //ALSO I WILL SHOW MY OWN WAY OF GETTING INFO FROM THE DATABASE
  7. $userid= $_SESSION['id'];
  8. $userinfo= mysql_query("SELECT * FROM `members` WHERE `id`='$userid'");
  9. //CREATE A QUERY ^^^
  10. $fetch= mysql_fetch_object($userinfo); //GET INFO FROM QUERY
  11. //NOW ITS TIME TO CODE A SIMPLE LAYOUT (JUST A LARGE TABLE) AND SOME CSS
  12. //HOPE THIS DOESNT CONFUSE YOU!
  13.  
  14. $getfaq_info= mysql_query("SELECT * FROM `faq_system`"); //CREATE QUERY TO GET TABLE INFO
  15. $the= mysql_fetch_object($getfaq_info); //PREPARE TABLE INFO FOR USE IN PAGE
  16. ?>
  17. <html>
  18. <head><title>FAQ SYSTEM</title>
  19. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  20. <style type="text/css">
  21. <!--
  22. body,td,th {
  23. font-family: Verdana, Arial, Helvetica, sans-serif;
  24. font-size: 10px;
  25. color: #FFFFFF;
  26. }
  27. body {
  28. background-color: #CCCCCC;
  29. margin-left: 0px;
  30. margin-top: 0px;
  31. margin-right: 0px;
  32. margin-bottom: 0px;
  33. }
  34. a:link {
  35. text-decoration: none;
  36. }
  37. a:visited {
  38. text-decoration: none;
  39. }
  40. a:hover {
  41. text-decoration: none;
  42. }
  43. a:active {
  44. text-decoration: none;
  45. }
  46. -->
  47. </style>
  48. </head>
  49. <body>
  50. <div align=center>
  51. <table width="80%" align="center" bgcolor="#333333" border="1" bordercolor="#000000" cellpadding=0 cellspacing=0 frame="box" rules="all">
  52. <tr><td bgcolor=red><div align=center><strong>FAQ SYSTEM</strong></div></td></tr>
  53. <tr><td>
  54. <div align=center>
  55. Welcome <? echo ucfirst($fetch->username); ?>. This page displays the sites faq system. It includes general, staff, bugs and terms of service information.
  56. </div>
  57. </td></tr>
  58. <tR><td bgcolor=red><div align=center><strong>GENERAL
  59. <?
  60. if ($fetch->userlevel >= "4"){ echo "<a href='faq_edit.php'>EDIT FAQ</a>";
  61. //IF USER IS A MODERATOR OR ABOVE LET THEM HAVE A LINK TO THE STAFF EDIT FAQ PAGE
  62. }
  63. ?>
  64. </strong></div></td></tr>
  65. <tr><td><br>&nbsp;
  66. <? echo "$the->general"; ?>
  67. <br>&nbsp;
  68. </td></tr>
  69. <tr><td bgcolor=red><div align=center><strong>STAFF
  70. <?
  71. if ($fetch->userlevel == "6"){ echo "<a href='faq_edit.php'>EDIT FAQ</a>"; }
  72. ?>
  73. </strong></div></td></tr>
  74. <tr><td><br>&nbsp;
  75. <? echo "$the->staff"; ?>
  76. <br>&nbsp;
  77. </td></tr>
  78. <tr><td bgcolor=red><div align=center><strong>BUGS/EXPLOITS
  79. <?
  80. if ($fetch->userlevel == "6"){ echo "<a href='faq_edit.php'>EDIT FAQ</a>"; }
  81. ?>
  82. </strong></div></td></tr>
  83. <tr><td><br>&nbsp;
  84. <? echo "$the->bugs"; ?>
  85. <br>&nbsp;
  86. </td></tr>
  87. <tr><td bgcolor=red><div align=center><strong>TERMS OF SERVICE
  88. <?
  89. if ($fetch->userlevel == "6"){ echo "<a href='faq_edit.php'>EDIT FAQ</a>"; }
  90. ?>
  91. </strong></div></td></tr>
  92. <tr><td><br>&nbsp;
  93. <? echo "$the->tos"; ?>
  94. <br>&nbsp;
  95. </td></tr>
  96. <tR><td bgcolor=red><div align=center><strong>LAST UPDATED BY <? echo "".strtoupper($the->last_by).""; ?> ON THE <? echo "$the->last_update"; ?></strong></div></td></tR>
  97. </table>
  98.  
  99. </div>
  100. </body>
  101. </html>

Pretty long huh? Now u now the trouble i go through for you guys xD

And thats not it :o now we need to make an admin/moderator edit page for this faq system. We will be calling this page faq_edit.php
Again feel free to call it anything you like just al long as you change the links in the previous code ^^^ Heres the code for this script.

faq_edit.php:
PHP Code
  1. <?
  2. session_start();
  3. //OKAY I HAVNT USED YOUR LOTS USER SYSTEM BEFORE SO IM JUST GOING TO STICK TO WHATS ITS THE CONFIG AND USE HELP FROM THAT. HEHE HOPE YOU CAN UNDERSTAND ME :P
  4. require_once "config.php"; //FOR SECURITY TERMS I WILL USE REQUIRE ONCE INSTEAD OF INCLUDE
  5.  
  6. //ALSO I WILL SHOW MY OWN WAY OF GETTING INFO FROM THE DATABASE
  7. $userid= $_SESSION['id'];
  8. $userinfo= mysql_query("SELECT * FROM `members` WHERE `id`='$userid'");
  9. //CREATE A QUERY ^^^
  10. $fetch= mysql_fetch_object($userinfo); //GET INFO FROM QUERY
  11.  
  12. //OKAY NOW FOR THE LAYOUT, CSS AND ADMIN CHECKS ETC U NO THE DRILL :P
  13.  
  14. $getfaq_info= mysql_query("SELECT * FROM `faq_system`"); //CREATE QUERY TO GET TABLE INFO
  15. $the= mysql_fetch_object($getfaq_info); //PREPARE TABLE INFO FOR USE IN PAGE
  16. ?>
  17. <html>
  18. <head><title>FAQ SYSTEM FOR N00BS :P</title>
  19. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  20. <style type="text/css">
  21. <!--
  22. body,td,th {
  23. font-family: Verdana, Arial, Helvetica, sans-serif;
  24. font-size: 10px;
  25. color: #FFFFFF;
  26. }
  27. body {
  28. background-color: #CCCCCC;
  29. margin-left: 0px;
  30. margin-top: 0px;
  31. margin-right: 0px;
  32. margin-bottom: 0px;
  33. }
  34. a:link {
  35. text-decoration: none;
  36. }
  37. a:visited {
  38. text-decoration: none;
  39. }
  40. a:hover {
  41. text-decoration: none;
  42. }
  43. a:active {
  44. text-decoration: none;
  45. }
  46. -->
  47. </style>
  48. </head>
  49. <body>
  50. <div align=center>
  51. <table width="80%" align="center" bgcolor="#333333" border="1" bordercolor="#000000" cellpadding=0 cellspacing=0 frame="box" rules="all">
  52. <tr><td bgcolor=red><div align=center><strong>FAQ SYSTEM - ADMIN CP</strong></div></td></tr>
  53. <tR><td><div align=center>
  54. <? if ($fetch->userlevel < "4"){ ?>
  55. WhAt?!? You can't be here! Only moderators or admins are allowed to see this page!
  56. <? }else{ //HEHE END OF ADMIN/MOD CHECK ?>
  57. Welcome <? echo ucfirst($fetch->username); ?>. Having a nice day, nice cuppa tea? Good. Heres your cpanel...<br>
  58. <font color=red>RETURN TO FAQS?</font>
  59. <b>EDIT GENERAL INFO</b>
  60. <textarea style="background-color:#FFFFFF; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; height:150; width:80%;" name="edit_general"><? echo "$the->general"; ?></textarea>
  61. <b>EDIT STAFF INFO</b>
  62. <textarea style="background-color:#FFFFFF; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; height:150; width:80%;" name="edit_staff"><? echo "$the->staff"; ?></textarea>
  63. <b>EDIT BUGS/EXPLOIT INFO</b>
  64. <textarea style="background-color:#FFFFFF; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; height:150; width:80%;" name="edit_bugs"><? echo "$the->bugs"; ?></textarea>
  65. <b>EDIT TERMS OF SERVICE INFO</b>
  66. <textarea style="background-color:#FFFFFF; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; height:150; width:80%;" name="edit_tos"><? echo "$the->tos"; ?></textarea>
  67. <input type=submit style="background-color:#FFFFFF; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px;" name=edit value="Change" onclick="this.value='Changing...';" />
  68.  
  69. <?
  70. if (strip_tags($_POST['edit']) && strip_tags($_POST['edit_general']) && strip_tags($_POST['edit_staff']) && strip_tags($_POST['edit_bugs']) && strip_tags($_POST['edit_tos'])){
  71. //IF ALL THE FORMS ABOVE ARE FILLED IN :P
  72. $new_general= $_POST['edit_general'];
  73. $new_staff= $_POST['edit_staff'];
  74. $new_bugs= $_POST['edit_bugs'];
  75. $new_tos= $_POST['edit_tos'];
  76.  
  77. $date = gmdate('Y-m-d h:i:s'); //DATE AND TIME READY TO INSERT INTO DB
  78. mysql_query("UPDATE `faq_system` SET `general`='$new_general', `staff`='$new_staff', `bugs`='$new_bugs', `tos`='$new_tos', `last_by`='$fetch->username', `last_update`='$date'");
  79. //WHO CARES LET UPDATE ALL OF THEM... EVEN THO THERES ONLY 1 :P
  80.  
  81. echo "<script>window.location='faq_edit.php';</script>"; //REFRESH THE PAGE
  82. }
  83. ?>
  84.  
  85.  
  86. <? } ?>
  87. </div></td></tR>
  88. </table>
  89. </div>
  90. </body>
  91. </html>


Okay im warning you there could be some errors ;) so please post comments here if their are. I will not SCREAM or BITE u if uve made the mistake yourself. In return u wont do the same :)

Thanks. Now your faq system should be ready to use.
ilyas-shezad's Avatar
Views:
3,331
Rating:
Posted on Saturday 5th January 2008 at 08:12 PM
ShadowMage
ShadowMage's Avatar
[*code] without the star :P
Posted on Saturday 5th January 2008 at 07:32 PM
DanielXP
DanielXP's Avatar
Remember bbcodes. [php] or [code]
Posted on Saturday 5th January 2008 at 06:32 PM
kaila
kaila's Avatar
Jozo, the problem is on the Control panel. The form was never really started.

To make this work, find this code:


<? }else{ //HEHE END OF ADMIN/MOD CHECK ?>
Welcome <? echo ucfirst($fetch->username); ?>. Having a nice day, nice cuppa tea? Good. Heres your cpanel...<br>
<font color=red>RETURN TO FAQS?</font><br /><br />

And after it, add:

<form method="post" name="faqedit">

After the submit button, end the form (</form>)


Good tutorial :)
Posted on Monday 24th December 2007 at 07:33 PM
Jozo
Jozo's Avatar
When you click change, it just stays on changing for yonks.. :(
Posted on Tuesday 28th August 2007 at 05:40 PM
Dalez
Dalez's Avatar
Nice - havn't tried yet - can't register on myne yet ;p
Posted on Thursday 16th August 2007 at 07:07 AM
gbt91
gbt91's Avatar
ehy ily thx
Posted on Wednesday 15th August 2007 at 10:25 PM