web statistics

CREATING A PHP POWERED FAQ SYSTEM

Step 4 - The adding FAQ page.
Ok now we have our config.php page to connect to the database we need a page that add things to the database!

So create a new file called addfaq.php

And put this code into it:

<?

include 'config.php'; // includes config

if(!$_POST['addfaq']) { // if the user has not submitted 'addfaq':

echo "

<form method='post' action=''>
Faq Question: <br/><br/>

<input type='text' name='q' value='' />
<br/><br/>
Answer To Question: <br/><br/>

<input type='text' name='a' value='' />
<br/><br/>
<input type='submit' name='addfaq' value='Add' />
</form>
"; // Add Faq Form

}

else // if the user has submitted 'addfaq':
{
if ($_POST['addfaq']) { // if user pressed 'add'

$question = htmlspecialchars($_POST['q'], ENT_QUOTES); // $question = value of the form's question input box

$answer = htmlspecialchars($_POST['a'], ENT_QUOTES); // $answer = value of the form's answer input box

$query = "INSERT INTO faq SET faqname = '$question', faqanswer = '$answer'"; // Query text to insert

if (mysql_query("$query")) { // if the query works...

echo "Frequently asked question added"; // write Frequently asked question added

}

else { // if it doesnt work...

echo "Could not add FAQ"; // write Could not add FAQ

}



}
}

?>


// = Comment,

Ok so what that basically means is that if the user has not pressed the submit button called addfaq, write the submit form, if it has then insert the data into the database, for example $question = $_POST['q']; means the variable $question = the data from the form's input box with the name 'q' and then it inserts it into the database with the mysql_query, and if its successful it will write "Frequently asked question added" if not it will write "Could not add FAQ".

So we have our add faq system, now we need to display it

Pages: « First   1   2   3   4   5   6   Last »

Share del.icio.us Digg it reddit
Current tags

faq lja24 php powered sexy sql system
Rate this tutorial

4

Log In to rate this tutorial
Comments
PricelessNL on 04/03/07 at 12:38
hi, i found youre tutorial on the web when i was searching for a tut to create a faq. first i want to say nice tutorial :)
but i have a question. Is there a possibillity of a Edit.php page where you could edit the questions or answers if you made a error
Add Comment
Log In to post your comments

BannerFans.com
Google PageRank Checker - From PageRankr
 
&nsbp;