65.9K
CodeProject is changing. Read more.
Home

AJAX Generic Comments Module

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.17/5 (12 votes)

Jul 28, 2006

CPOL

1 min read

viewsIcon

67501

downloadIcon

711

Source code for a generic comments module, using AJAX/PHP/MySQL.

Introduction

This article will show you how to use a generic comments module which is implemented using PHP 4.0, MySQL, and AJAX.

This module is now running here; you can see it in every project review page.

Sample screenshot

Here, the user will enter his information and his comments:

Sample screenshot

When the user clicks on the submit comment button, the comment will be submitted without any page refresh, and the new comment will appear in the page.

Installing database scripts

The database is located in the source code folder in sourcecode/sql/script.sql; just open your MySQL client, and run it to install the database.

How can I add it to my code

  1. Include the files of the comments module in your application folder.
  2. In your code, include the comments.php file to be able to show the comments module.
  3. The comments will show specific comments of every page, according to the ForiegnID which identifies the page which will show the comment (i.e., the ForiegnID of an article can be "A"+$i where $i is the ID of the article in your application database; so, you can use the same module in many pages (articles, news, reviews,..))
<?php
$i =0; // $i can be your article id

$ForeignID = "comment-$i" ; 
require("includes/comments.php");?>