Search
Left Quote    Choose a job you love, and you will never have to work a day in your life.
- Confucius    
Right Quote
 
[login] | [Register]
 

Building a Comments Script

by: bs0d
Page: 3 of 4
(View All)

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:



Flood Control


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.


1  |  2  |  3  |  4  |  
Next »


Comments:

  keefy
  Subject: "Testing" Date: Sep 24 2007 at 5:55 pm    

Looks Good :)
  keefy
  Subject: "smilies" Date: Sep 24 2007 at 6:04 pm    

is there any way you could make it to insert smilies ? this would make it 100%
  bs0d
  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 basically use regular expression (regex) functions like: preg_match() and preg_replace() and also str_replace() to replace the BBCode characters in the message to HTML.

For example: You want to use :) as a smilie. You would use str_replace to replace :) with HTML path to the smilie. Then, store that in the DB. When you display it, it displays hte smilie. preg_replace and preg_match using regex are for the more complicated BBcode items, like quotes and links and such. Good luck!
You Must be logged in or a member to comment.


Tutorial Stats

Tutorial Stats

342,259 Views
41 Total Comments
4.75 Rating of 5 (4 Votes)

Options

Tutorial Options

· Login to Rate This Article
· Login to Post a Comment
· Read more by this author
Digg This Article! Del.icio.us: Bookmark This Article Reddit: Bookmark This Article BlinkList: Blink This Article! YahooMyWeb BlogMarks: Add This Mark! Furl: Save This Article Spurl: Mark This Article

Articles

Related    

· Simple PHP Tutorial
· One File Website
· Pagination with PHP
· Complete Members System
· Variable Scope



"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank