Building a Comments Script
|Page: 3 of 4
Check Valid Contact Data
Immediately following the code above, we analyze the contact information. Contact information should
be in the form of email or url of their website. This code will check if mailto: or http:// exists.
And if it does not, we will add it onto whatever they typed. P.S: this method is borrowed from
misterhaan. Look below:
Next we will execute code aimed at preventing multiple comments duing one setting. We run a query that
selects comments matching their IP. Then check if the last comment was made within 5 minutes, if so-
tell them to stop posting so fast, if not- allow the comment to fall through. Here is the code:
Inserting The Comment and Refreshing the Page
This is the final portion of the code. After this is complete, we display the form to submit
a comment. Anyways, we will run an insert query to add the data. The submit button has been pressed,
the input data has been validated, and we're all ready. After the insert query executes, we
use header(); to refresh the page and show the poster their comment. Observe:
Notice we're using addslashes(); to insert the data into the database. And the values from the
form submission are available through $_POST. The input fields are assigned a name, and we put
that name inside $_POST to access it specifically.
*Note: Notice the article id is accessed by $_GET. That is because in this situation, the article
id number is available in the URL, like this: site.com/article.php?id=XXX .
And at the end, is where we're refreshing the page. If this does not work for you, you might try
using, ob_start(); at the top of your script. This might fix a reload problem - should it arise.
At the end you see, "#comments". This is an anchor name I setup in the code of the article where
I put the code to insert comments for that page. So by adding this to the end of the header(); it
will refresh down to comments by the anchor. That is basic HTML.
| Subject: "Testing"
Date: Sep 24 2007 at 5:55 pm
|Looks Good :)
| Subject: "smilies"
Date: Sep 24 2007 at 6:04 pm
|is there any
way you could
make it to
? this would
make it 100%
| Subject: "Smilies"
Date: Sep 25 2007 at 3:06 am
|You can indeed
add smilies. I
don't have an
article up on
BBCode, but you
to replace the
the message to
You want to use
:) as a smilie.
You would use
replace :) with
HTML path to
that in the DB.
display it, it
using regex are
for the more
like quotes and
links and such.
||Rating of 5 (4 Votes)