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:
CREATE TABLE `faq_system` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`general` TEXT NOT NULL ,
`staff` TEXT NOT NULL ,
`bugs` TEXT NOT NULL ,
`tos` TEXT NOT NULL ,
`last_by` VARCHAR( 25 ) NOT NULL ,
`last_update` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
) 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...
INSERT INTO `faq_system` (
`id` ,
`general` ,
`staff` ,
`bugs` ,
`tos` ,
`last_by` ,
`last_update`
)
VALUES (
NULL , 'None', 'None', 'None', 'None', 'No one', '0000-00-00 00:00:00'
);
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:
<?
session_start();
//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
require_once "config.php"; //FOR SECURITY TERMS I WILL USE REQUIRE ONCE INSTEAD OF INCLUDE
//ALSO I WILL SHOW MY OWN WAY OF GETTING INFO FROM THE DATABASE
$userid= $_SESSION['id'];
$userinfo= mysql_query("SELECT * FROM `members` WHERE `id`='$userid'");
//CREATE A QUERY ^^^
$fetch= mysql_fetch_object($userinfo); //GET INFO FROM QUERY
//NOW ITS TIME TO CODE A SIMPLE LAYOUT (JUST A LARGE TABLE) AND SOME CSS
//HOPE THIS DOESNT CONFUSE YOU!
$getfaq_info= mysql_query("SELECT * FROM `faq_system`"); //CREATE QUERY TO GET TABLE INFO
$the= mysql_fetch_object($getfaq_info); //PREPARE TABLE INFO FOR USE IN PAGE
?>
<html>
<head><title>FAQ SYSTEM</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body,td,th {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
body {
background-color: #CCCCCC;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
-->
</style>
</head>
<body>
<div align=center>
<table width="80%" align="center" bgcolor="#333333" border="1" bordercolor="#000000" cellpadding=0 cellspacing=0 frame="box" rules="all">
<tr><td bgcolor=red><div align=center><strong>FAQ SYSTEM</strong></div></td></tr>
<tr><td>
<div align=center>
Welcome <? echo ucfirst($fetch->username); ?>. This page displays the sites faq system. It includes general, staff, bugs and terms of service information.
</div>
</td></tr>
<tR><td bgcolor=red><div align=center><strong>GENERAL
<?
if ($fetch->userlevel >= "4"){ echo "<a href='faq_edit.php'>EDIT FAQ</a>";
//IF USER IS A MODERATOR OR ABOVE LET THEM HAVE A LINK TO THE STAFF EDIT FAQ PAGE
}
?>
</strong></div></td></tr>
<tr><td><br>
<? echo "$the->general"; ?>
<br>
</td></tr>
<tr><td bgcolor=red><div align=center><strong>STAFF
<?
if ($fetch->userlevel == "6"){ echo "<a href='faq_edit.php'>EDIT FAQ</a>"; }
?>
</strong></div></td></tr>
<tr><td><br>
<? echo "$the->staff"; ?>
<br>
</td></tr>
<tr><td bgcolor=red><div align=center><strong>BUGS/EXPLOITS
<?
if ($fetch->userlevel == "6"){ echo "<a href='faq_edit.php'>EDIT FAQ</a>"; }
?>
</strong></div></td></tr>
<tr><td><br>
<? echo "$the->bugs"; ?>
<br>
</td></tr>
<tr><td bgcolor=red><div align=center><strong>TERMS OF SERVICE
<?
if ($fetch->userlevel == "6"){ echo "<a href='faq_edit.php'>EDIT FAQ</a>"; }
?>
</strong></div></td></tr>
<tr><td><br>
<? echo "$the->tos"; ?>
<br>
</td></tr>
<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>
</table>
</div>
</body>
</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:
<?
session_start();
//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
require_once "config.php"; //FOR SECURITY TERMS I WILL USE REQUIRE ONCE INSTEAD OF INCLUDE
//ALSO I WILL SHOW MY OWN WAY OF GETTING INFO FROM THE DATABASE
$userid= $_SESSION['id'];
$userinfo= mysql_query("SELECT * FROM `members` WHERE `id`='$userid'");
//CREATE A QUERY ^^^
$fetch= mysql_fetch_object($userinfo); //GET INFO FROM QUERY
//OKAY NOW FOR THE LAYOUT, CSS AND ADMIN CHECKS ETC U NO THE DRILL :P
$getfaq_info= mysql_query("SELECT * FROM `faq_system`"); //CREATE QUERY TO GET TABLE INFO
$the= mysql_fetch_object($getfaq_info); //PREPARE TABLE INFO FOR USE IN PAGE
?>
<html>
<head><title>FAQ SYSTEM FOR N00BS :P</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body,td,th {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FFFFFF;
}
body {
background-color: #CCCCCC;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
-->
</style>
</head>
<body>
<div align=center>
<table width="80%" align="center" bgcolor="#333333" border="1" bordercolor="#000000" cellpadding=0 cellspacing=0 frame="box" rules="all">
<tr><td bgcolor=red><div align=center><strong>FAQ SYSTEM - ADMIN CP</strong></div></td></tr>
<tR><td><div align=center>
<? if ($fetch->userlevel < "4"){ ?>
WhAt?!? You can't be here! Only moderators or admins are allowed to see this page!
<? }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>
<b>EDIT GENERAL INFO</b>
<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>
<b>EDIT STAFF INFO</b>
<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>
<b>EDIT BUGS/EXPLOIT INFO</b>
<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>
<b>EDIT TERMS OF SERVICE INFO</b>
<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>
<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...';" />
<?
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'])){
//IF ALL THE FORMS ABOVE ARE FILLED IN :P
$new_general= $_POST['edit_general'];
$new_staff= $_POST['edit_staff'];
$new_bugs= $_POST['edit_bugs'];
$new_tos= $_POST['edit_tos'];
$date = gmdate('Y-m-d h:i:s'); //DATE AND TIME READY TO INSERT INTO DB
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'");
//WHO CARES LET UPDATE ALL OF THEM... EVEN THO THERES ONLY 1 :P
echo "<script>window.location='faq_edit.php';</script>"; //REFRESH THE PAGE
}
?>
<? } ?>
</div></td></tR>
</table>
</div>
</body>
</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.
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 :)