Comment Form / Post Feedback Tutorial

Allow users to display and post comments on a page

Comment Form / Feedback Script Background

Feedback is very valuable to not only the web designers, but to other visitors as well. That was why I designed a simple comment form script for my site. I have had multiple requests for a tutorial on this, so I decided to write one. This is a fairly advanced tutorial, and I don't go into a lot of detail to explain my script. Now on to the tutorial...

Database: Create MySQL table

All the data from the comments form is stored in a MySQL database. If you do not have a database created, create one now. Now use the following MySQL command to create a new table to store the information:

CREATE TABLE `comments` (
  `commentid` int(11) NOT NULL auto_increment,
  `tutorialid` int(11) NOT NULL default '0',
  `name` text NOT NULL,
  `url` text NOT NULL,
  `comment` text NOT NULL,
  `email` text NOT NULL,
  `date` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`commentid`),
  KEY `tutorialid` (`tutorialid`)
)

The script

1. Create a new php file, and name it "inc_rate.php". This file will store 5 functions: a date parsing script, a database connection function, a bbcode function, a function to display existing comments, and another to create an add comments form. Now add the following code to that page. You will need to input your database information at the top of the page. Explanations for the code are included as comments (in blue).




<?
//Please set the following variables for your MySQL database:
//Please set the following variables for your MySQL database:
//it is highly recommended that you restrict access for the user for security reasons
//it only needs "INSERT" privileges

$db_hostname = "localhost";  //usually "localhost be default"
$db_username = "";  //your user name
$db_pass = "";  //the password for your user
$db_name = "";  //the name of the database


/*MYSQL DATABASE CONNECTION/ TRACKING FUNCTIONS
--------------------------------------*/
// connect to database
$dbh = mysql_connect ($db_hostname, $db_username, $db_pass) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($db_name);



//for security, html is not allowed, so bbcode is used for formatting

//START 3rd PARTY CODE:  I did not write this
/************************************************/
/*              BBCode v1.0a                    */
/*              Date: 03/2003                   */
/*                                              */
/*      A simple and effective script that      */
/*      allows you to implement bbcode type     */
/*      behaviour on your php website.          */
/*                                              */
/*      Contact: bbcode@netgem.freeserve.co.uk  */
/*                                              */
/*      Usage:                                  */
/*                                              */
/*      Put the following line at the top of    */
/*      the page you want to have the bbocde    */
/*      in...(assumes both pages are in the     */
/*      folder                                  */
/*                                              */
/*      include("bbCode.php");                  */
/*                                              */
/*      Pass the text to the function:          */
/*                                              */
/*      $mytext = BBCode("This is my BBCODE");  */
/*      or                                      */
/*      $mytext = "This is my text";            */
/*      $mytext = BBCode($mytext);              */
/*                                              */
/*      echo $mytext;                           */
/*                                              */
/************************************************/
?>
<style type="text/css">
<!--
body    {
        font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 12px;
}

.bold {
        font-weight: bold;
}

.italics {
        font-style: italic;
}

.underline {
        text-decoration: underline;
}

.strikethrough {
        text-decoration: line-through;
}

.overline {
        text-decoration: overline;
}

.sized {
        text-size:
}

.quotecodeheader {
        font-family: Verdana, arial, helvetica, sans-serif;
        font-size: 12px;
        font-weight: bold;
}

.codebody {
        background-color: #FFFFFF;
    font-family: Courier new, courier, mono;
    font-size: 12px;
    color: #006600;
    border: 1px solid #BFBFBF;
}

.quotebody {
        background-color: #FFFFFF;
    font-family: Courier new, courier, mono;
    font-size: 12px;
    color: #660002;
        border: 1px solid #BFBFBF;
}

.listbullet {
        list-style-type: disc;
        list-style-position: inside;
}

.listdecimal {
        list-style-type: decimal;
        list-style-position: inside;
}

.listlowerroman {
        list-style-type: lower-roman;
        list-style-position: inside;
}

.listupperroman {
        list-style-type: upper-roman;
        list-style-position: inside;
}

.listloweralpha {
        list-style-type: lower-alpha;
        list-style-position: inside;
}

.listupperalpha {
        list-style-type: upper-alpha;
        list-style-position: inside;
}
-->
</style>

<?php
        //Local copy

        function BBCode($Text)
            {
                // Replace any html brackets with HTML Entities to prevent executing HTML or script
            // Don't use strip_tags here because it breaks [url] search by replacing & with amp
            $Text = str_replace("<", "&lt;", $Text);
            $Text = str_replace(">", "&gt;", $Text);



            // Set up the parameters for a URL search string
            $URLSearchString = " a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'";
            // Set up the parameters for a MAIL search string
            $MAILSearchString = $URLSearchString . " a-zA-Z0-9\.@";

                        //Non BB URL Search
                        //$Text = eregi_replace("([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", "<a href=\"\\1://\\2\\3\" target=\"_blank\" target=\"_new\">\\1://\\2\\3</a>", $Text);
                //$Text = eregi_replace("(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))", "<a href=\"mailto:\\1\" target=\"_new\">\\1</a>", $Text);
                if (substr($Text,0, 7) == "http://"){
            $Text = eregi_replace("([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", "<a href=\"\\1://\\2\\3\">\\1://\\2\\3</a>", $Text);
                 // Convert new line chars to html <br /> tags
            $Text = nl2br($Text);
                        } else {
            // Perform URL Search
            $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/", '<a href="javascript:go(\'$1\',\'new\')">$1</a>', $Text);
            $Text = preg_replace("(\[url\=([$URLSearchString]*)\](.+?)\[/url\])", '<a href="javascript:go(\'$1\',\'new\')">$2</a>', $Text);
                        //$Text = preg_replace("(\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[/url\])", '<a href="$1" target="_blank">$2</a>', $Text);
                         // Convert new line chars to html <br /> tags
            $Text = nl2br($Text);
                        }
            // Perform MAIL Search
            $Text = preg_replace("(\[mail\]([$MAILSearchString]*)\[/mail\])", '<a href="mailto:$1">$1</a>', $Text);
            $Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.+?)\[\/mail\]/", '<a href="mailto:$1">$2</a>', $Text);

            // Check for bold text
            $Text = preg_replace("(\[b\](.+?)\[\/b])is",'<span class="bold">$1</span>',$Text);

            // Check for Italics text
            $Text = preg_replace("(\[i\](.+?)\[\/i\])is",'<span class="italics">$1</span>',$Text);

            // Check for Underline text
            $Text = preg_replace("(\[u\](.+?)\[\/u\])is",'<span class="underline">$1</span>',$Text);

            // Check for strike-through text
            $Text = preg_replace("(\[s\](.+?)\[\/s\])is",'<span class="strikethrough">$1</span>',$Text);

            // Check for over-line text
            $Text = preg_replace("(\[o\](.+?)\[\/o\])is",'<span class="overline">$1</span>',$Text);

            // Check for colored text
            $Text = preg_replace("(\[color=(.+?)\](.+?)\[\/color\])is","<span style=\"color: $1\">$2</span>",$Text);

            // Check for sized text
            $Text = preg_replace("(\[size=(.+?)\](.+?)\[\/size\])is","<span style=\"font-size: $1px\">$2</span>",$Text);

            // Check for list text
            $Text = preg_replace("/\[list\](.+?)\[\/list\]/is", '<ul class="listbullet">$1</ul>' ,$Text);
            $Text = preg_replace("/\[list=1\](.+?)\[\/list\]/is", '<ul class="listdecimal">$1</ul>' ,$Text);
            $Text = preg_replace("/\[list=i\](.+?)\[\/list\]/s", '<ul class="listlowerroman">$1</ul>' ,$Text);
            $Text = preg_replace("/\[list=I\](.+?)\[\/list\]/s", '<ul class="listupperroman">$1</ul>' ,$Text);
            $Text = preg_replace("/\[list=a\](.+?)\[\/list\]/s", '<ul class="listloweralpha">$1</ul>' ,$Text);
            $Text = preg_replace("/\[list=A\](.+?)\[\/list\]/s", '<ul class="listupperalpha">$1</ul>' ,$Text);
            $Text = str_replace("[*]", "<li>", $Text);

            // Check for font change text
            $Text = preg_replace("(\[font=(.+?)\](.+?)\[\/font\])","<span style=\"font-family: $1;\">$2</span>",$Text);

            // Declare the format for [code] layout
            $CodeLayout = '<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td class="quotecodeheader"> Code:</td>
                                </tr>
                                <tr>
                                    <td class="codebody">$1</td>
                                </tr>
                           </table>';
            // Check for [code] text
            $Text = preg_replace("/\[code\](.+?)\[\/code\]/is","$CodeLayout", $Text);

            // Declare the format for [quote] layout
            $QuoteLayout = '<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td class="quotecodeheader"> Quote:</td>
                                </tr>
                                <tr>
                                    <td class="quotebody">$1</td>
                                </tr>
                           </table>';

            // Check for [code] text
            $Text = preg_replace("/\[quote\](.+?)\[\/quote\]/is","$QuoteLayout", $Text);

            // Images
            // [img]pathtoimage[/img]
            $Text = preg_replace("/\[img\](.+?)\[\/img\]/", '<img src="$1">', $Text);

            // [img=widthxheight]image source[/img]
            $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/", '<img src="$3" height="$2" width="$1">', $Text);

                return $Text;
                }


//END 3rd PARTY CODE

//quick script to make the data look nice
function formatDate($val)
  {
      list($date, $time) = explode(" ", $val);
      list($year, $month, $day) = explode("-", $date);
      list($hour, $minute, $second) = explode (":", $time);
      return date("l, m.j.y @ H:ia", mktime($hour, $minute, $second, $month, $day, $year));
  }



function getComments($tutid){
//creates a function that can easily be called from any page

//create the css code to make the form look good.  You can edit this to change colors, etc:
echo "
<style>
/*COMMENTS
*------------------------------------*/

.postedby {
        padding: 0 0 0 18px;
        background: url(images/abullet.gif) no-repeat 0 4px;
        }
        
h3.formtitle {
        margin : 0px 0px 0px 0px;
        border-bottom: 1px dotted #ccc;
        padding-bottom: 8px;
        }

.commentbody {
        border-top: 1px dotted #ccc;
        }
        
/*gray box*/
.submitcomment, #submitcomment, #currentcomments, #rating, .textad {
        background-color: #F5F5F5;
        border: 1px dotted #ccc;
        padding: 5px;
        padding: 5px;
        margin: 20px 0px 0px 0px;
        }


/*FORMS
*------------------------------------*/

.form {
        background-color: #FAFAFA;
        border: solid 1px #C6C6C6;
        padding: 2px;
        }

.formtext {
        background-color: #FAFAFA;
        border: solid 1px #C6C6C6;
        padding: 2px;
        border-bottom: 1px dotted #ccc
        }

.form:hover, .formtext:hover {
        background: white;
        }
        
.form:focus, .formtext:focus {
        background: white;
        border: solid 1px #000000;
        }
        
.submit {
        background-color: #D3D3D3;
        border: solid 1px #C6C6C6;
        border-right:  solid 1px #9A9A9A;
        border-bottom:  solid 1px #9A9A9A;
        }
        
.submit:hover, .submit:focus {
        background: #EDEDED;
        }
        </style>

        
        ";
//fetch all comments from database where the tutorial number is the one you are asking for
        $commentquery = mysql_query("SELECT * FROM comments WHERE tutorialid='$tutid' ORDER BY date") or die(mysql_error());
//find the number of comments
        $commentNum = mysql_num_rows($commentquery);
//create a headline
        echo "<div id=\"currentcomments\" class=\"submitcomment\"><h3 class=\"formtitle\">Current Comments</h3>\n";
        echo $commentNum . " comments so far (<a href=\"#post\">post your own</a>)\n";
//for each comment in the database in the right category number...
        while($commentrow = mysql_fetch_row($commentquery)){
//for security, parse through the bbcode script
//the number corresponds to the column (the message is always stored in column 4
//COUTING STARTS at 0!!!
        $commentbb = BBCode($commentrow[4]);
//create the right date format
                $commentDate = formatDate($commentrow[6]);

                echo "<div class=\"commentbody\" id=\"$commentrow[0]\">\n
                <p>$commentbb</p>\n
                <p class=\"postedby\">Posted by ";
                if($commentrow[3]){
                echo "<a href=\"$commentrow[3]\">$commentrow[2]</a> ";
                } else {
                echo "$commentrow[2] ";
                }
                echo "on $commentDate | #$commentrow[0]</p>\n
                \n</div>";

        }
        echo "</div>";
}

function submitComments($tutid2,$tuturl){
//a javascript script to make sure all the required fields are filled in
?>
<script language="javascript">

function form_Validator(form)
{

  if (form.name.value == "")
  {
    alert("Please enter your name.");
    form.name.focus();
        return (false);
     }

  if (form.message.value == "")
  {
    alert("Please enter your message.");
    form.message.focus();
    return (false);
  }
  
  return (true);
  }
  //-->
  </script>
<?php
//create the form to submit comments
//you can add more fields, but make sure you add them to the db table and the page, submitcomment.php
        echo "
<a name=\"post\">
<div id=\"submitcomment\" class=\"submitcomment\">
<form name=\"submitcomment\" method=\"post\" action=\"submitcomment.php\" onSubmit=\" return form_Validator(this)\">
<table width=\"100%\">
                <tr>
                                <th colspan=\"2\"><h3 class=\"formtitle\">Leave your comment:</h3></th>
                </tr>
                <tr>

                                <th scope=\"row\"><p class=\"req\">Name:</p></th>
                                <td><input class=\"form\" tabindex=\"1\" id=\"name\" name=\"name\" /></td>
                </tr>
                <tr>
                                <th scope=\"row\"><p class=\"opt\">Email:</p></th>
                                <td><input class=\"form\" tabindex=\"2\" id=\"email\" name=\"email\" /></td>
                </tr>
                <tr>

                                <th scope=\"row\"><p class=\"opt\">URL:</p></th>
                                <td><input class=\"form\" tabindex=\"3\" id=\"url\" name=\"url\" /></td>
                </tr>
                <tr valign=\"top\">
                                <th scope=\"row\"><p class=\"req\">Comments:</p><br /></th>
                                <td><textarea class=\"formtext\" tabindex=\"4\" id=\"message\" name=\"message\" rows=\"10\" cols=\"50\"></textarea></td>
                </tr>

                <tr>    
                                <td>&nbsp;</td>
                                <td><input type=\"submit\" name=\"post\" class=\"submit\" value=\"Submit Comment\" /><br />
                                <p>Note:  Emails will not be visible or used in any way, and are not required.  Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted. </p>

<p>No HTML code is allowed.  Line breaks will be converted automatically.  URLs will be auto-linked.  Please use BBCode to format your text.</p>

</td>
                </tr>
</table>
<input type=\"hidden\" name=\"tuturl\" value=\"$tuturl\" />
<input type=\"hidden\" name=\"tutid2\" value=\"$tutid2\" />
</form>


</div>
";
}
?>




2. Create another php file, and call it "submitcomment.php". This page will handle for form input and submit it to the database. Add the following code to that page. You will need to input your database information at the top of the page.


<?php
//Please set the following variables for your mysql database:
$db_hostname = "localhost";  //usually "localhost be default"
$db_username = "";  //your user name
$db_pass = "";  //the password for your user
$db_name = "";  //the name of the database


/*MYSQL DATABASE CONNECTION/ TRACKING FUNCTIONS
--------------------------------------*/
// connect to database
$dbh = mysql_connect ($db_hostname, $db_username, $db_pass) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($db_name);


$tuturl = $_POST["tuturl"];
$tutid2 = $_POST["tutid2"];
$name = $_POST["name"];
$url = $_POST["url"];
$email = $_POST["email"];
$message = $_POST["message"];

$sendcomment = mysql_query("INSERT INTO comments SET tutorialid='$tutid2', name='$name', url='$url', email='$email', comment='$message', date=now()");
if($sendcomment){
//header("Location: $tuturl");
echo "<h1>Submission Successful</h1>";
echo "Your comment has been submitted.  You will now be redirected back to the last page you visited.  Thanks!";
echo "<meta http-equiv='refresh' content='2;URL=$tuturl'>";
} else {
echo "There was an error with the submission. ";
}

?>


	

Finishing touches: Add to a page

Now we will add the submit comment form and display any exhisting comments to a page. Add the following code to your page where you want the comments to be displayed. Make sure the page is a php file.:

<?php
require('inc_rate.php');
getComments("1");
submitComments("1","$PHP_SELF");
?>

Replace "1" with a unique number for the page. For example, for this page, I use "22".

Tweaks

To order the list by newest posts first, find the line:

$commentquery = mysql_query("SELECT * FROM comments WHERE tutorialid='$tutid' ORDER BY date") or die(mysql_error());
And replace it with:
$commentquery = mysql_query("SELECT * FROM comments WHERE tutorialid='$tutid' ORDER BY date DESC") or die(mysql_error());

Final Code

If you are having any trouble, try downloading the script and tweaking it for your site. Here is all the final pages in a zip file:

commentscript.zip : 5 files

Hope this tutorial was useful. It is a fairly simple script, so adding fields, etc. should be easy. Have a great day!

Brian Zimmer is a graphics and web designer with over 4 years of experience in Paint Shop Pro, HTML, CSS, Javascript, SEO, PHP, and MySQL. His services include professional and affordable freelance web and graphic design. He is the webmaster of http://www.zimmertech.com, and you can contact him through email at brian@zimmertech.com.

Back to Top

Click here to return to ZimmerTech, or click here to view other tutorials.

Rate this Tutorial

Rate this Tutorial:

Current Rating:

0 out of 50.47/ 5.00 with 610 votes.

Current Comments

684 comments so far (post your own)

hi

Posted by lala on Thursday, 10.21.04 @ 06:34pm | #201

Nice tutorial!

Posted by Venom on Friday, 11.5.04 @ 10:39am | #207

Nice script!

I only miss one thing: the ability to use buttons to insert the BBcode...

Cheerz!

Posted by Freddy on Friday, 11.5.04 @ 01:55pm | #208

Testing

Posted by Testing on Friday, 11.5.04 @ 10:10pm | #209

great tutorial! a couple whishes:

1) I know it must be easy but i can't figure out how to manipulate the text font and size for the form. no matter what i tweak, "name, Email, & URL" look the same. any help on this?

2) any info on how to sort the entries by another field value? i want my form to be an event list. i would like to add a field for the event date and sort entries by that date...

thanks for the script.

Posted by ck on Wednesday, 11.24.04 @ 07:14pm | #226

The font size was in the CSS file. I changed the script to remove that line. It looks fine in Firefox, but I didn't realize it looked horrible in IE. For reference, you can remove the changed font size by removing the line "font-size: 70%;" in inc_rate.

To sort by another field value, at the end of the MySQL query where it ways "ORDER BY date", and change it to the new column that you created.

Posted by Brian Zimmer (http://www.zimmertech.com)on Wednesday, 11.24.04 @ 10:20pm | #227

Nice system :) great work. Very easy to use. Thank you!

Posted by DD on Sunday, 12.12.04 @ 11:24pm | #243

How do I create Database? thank you

Posted by John (don't have one)on Thursday, 12.16.04 @ 09:03pm | #248

Ok ,but I have that same comments in every page on my website. I want to create differend comments on every page...

Sorry for my english :/

Posted by mono on Saturday, 12.18.04 @ 09:56am | #249

If you want to have different comments on each page, change the number when you call the function. For example, on one page paste in:

<?php
require('inc_rate.php');
getComments("1");
submitComments("1","$PHP_SELF");
>

And for your next page, paste in:

<?php
require('inc_rate.php');
getComments("2");
submitComments("2","$PHP_SELF");
>

And so on.

Posted by Brian Zimmer on Wednesday, 12.22.04 @ 07:55pm | #250

cool!

Posted by cory on Thursday, 02.10.05 @ 12:19am | #351

Hi Nice Script..

Posted by Sathiyan (www.hashprompt.com)on Thursday, 02.10.05 @ 05:47am | #352

Excellent script. While testing it I posted some comments which I now want to remove. Any way to do this?

Posted by Michael on Monday, 02.21.05 @ 05:27pm | #362

To edit or remove comments, you have to edit the database. I use phpMyAdmin, which is installed on my server.

Posted by Brian Zimmer (http://www.zimmertech.com/)on Monday, 02.21.05 @ 05:43pm | #363

basically, I want to display in groups of 10. How do I do this? Do I have to manually create a new page every time it hits 10 or is there a way for it to automatically create a page such hat when I hit 11 comments, the first one automatically goes to the 2nd page and so on (and when it hits 21, the 1st comment goes to 3rd page, next ten on 2nd page, last 10 on first page, etc). Also, once I do that, how would I call each page?

Posted by Chau (phaseiipangroove.com)on Wednesday, 02.23.05 @ 06:24am | #368

I would like to write a script that reads through the comments searching for obscene words and replacing them with an appropriate word or asterixes. Can I do this? If so, how? Thank you again.

Posted by Chau (www.phaseiipangroove.com)on Thursday, 02.24.05 @ 07:08am | #370

Only testing

Posted by Jorge (www.watanabe.jor.br)on Saturday, 02.26.05 @ 09:44pm | #374

Hello, I have a website that I display my artwork on, and I've been looking for some kind of script that will let my friends and anyone who looks at my page leave a comment on a picture. This is the first script I have found that leaves the comment on the page, but I don't think my host supports PHP... is there a simpler way of just having a few text fields and a text box to allow comments to be left? Thank you!

Posted by Laura (http://www.freewebs.com/vanillapaint/)on Tuesday, 03.1.05 @ 10:06pm | #376

Hello, a have problem with this script

"Table 'gtdesign_uk_db.comments' doesn't exist "

help please

Posted by gtdesign on Sunday, 03.6.05 @ 12:48pm | #382

This means that the table in your database doesn't exhist. Run the following SQL command for your database:

CREATE TABLE `comments` (
`commentid` int(11) NOT NULL auto_increment,
`tutorialid` int(11) NOT NULL default '0',
`name` text NOT NULL,
`url` text NOT NULL,
`comment` text NOT NULL,
`email` text NOT NULL,
`date` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`commentid`),
KEY `tutorialid` (`tutorialid`)


)

Posted by Brian Zimmer on Tuesday, 03.8.05 @ 05:44am | #385

well.. i tried everything.. and it still wont work for me.. please help.. i get this error:

I cannot connect to the database because: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46)

database information i use.. i'm pretty sure its correct... but its not working..
$db_hostname = "localhost"/;
$db_username = "aspkin"/;
$db_pass = "password"/;
$db_name = "mysql"/;

i uploaded all files, created the comments table.. help!

Posted by donny on Thursday, 03.10.05 @ 01:45am | #386

Hope this works well and I can incorporate it into my new site...

Posted by Jeremy Whittaker (www.ukpoet.com)on Friday, 03.18.05 @ 06:18pm | #418

looks like a cool script!

Posted by andre on Wednesday, 03.30.05 @ 04:45pm | #429

hi there! i was just wondering, how could i change the script to make the newest posts topmost?

thanks!

Posted by shaun (http://shaunh.com)on Thursday, 04.14.05 @ 09:16pm | #493

thanks for the tweak brian! :)

Posted by shaun on Saturday, 04.16.05 @ 03:07am | #494

can you do it WITHOUT php?

Posted by Katie (http://www.eonxl.net)on Tuesday, 04.19.05 @ 12:54am | #496

To make it easier to use maybe have a seperate .css file for it too.

Great work

Posted by fantastic on Tuesday, 04.19.05 @ 07:35pm | #498

Correct, it would be better to have a seperate css file. But for the sake of this tutorial, I tried to use as few files as possible.

Posted by Brian Zimmer on Wednesday, 04.20.05 @ 12:57am | #499

Excellent script.
For anyone who is interested a page to clear rows you don’t want from table.
On my website edgey.no-ip.com under useful links

Posted by mick (http://www.edgey.no-ip.com/)on Wednesday, 04.20.05 @ 05:01pm | #500

how do you change the font size and color ?

can somone helm me please

grtz wes

Posted by wesley on Saturday, 04.23.05 @ 02:31pm | #502

and also when I "submit" the submit page is stuck and refreshes al the time. When I look into my database there are a lot of posts whith nothing on it. What can I do about that ?

Thx

Posted by wesley on Saturday, 04.23.05 @ 02:41pm | #506

Change the font size and color by changing the CSS part of the inc_rate.php file. Look inside the <style> tags. Look up CSS tutorials to learn how to change the font size, color, etc.

The page should refresh to the original page, but the latest comment will not be shown because the page was not completely refreshed. Remove the line:

<meta http-equiv='refresh' content='2/;URL=$tuturl'>

If you don't want this.

Posted by Brian Zimmer on Saturday, 04.23.05 @ 08:16pm | #508

thanks a lot for this info, I'm gonna test it now

grtz wes

Posted by Wesley Luyten on Sunday, 04.24.05 @ 05:37pm | #509

hi

just wanted to say that this is the perfect script that ive been searching for the past week. customizable and more importantly applicable to multiple pages.

thank you Brian!! i really appreciate it:)

Posted by js on Sunday, 04.24.05 @ 11:07pm | #510

While testing it I posted some comments which I now want to remove. Any way to do this.
The script on my website does this so you don't need to use php admin just place script in same folder give it an obscure name so only you can run it.
On my website edgey.no-ip.com under useful links

Posted by mick (mick@edgey.no-ip.com)on Sunday, 05.1.05 @ 09:57am | #519

Wordwrap problem solved by adding this at about this point
$commentbb = BBCode($commentrow[4])/;


$newtext = wordwrap($commentbb, 30, "\n", 1)/;



//create the right date format
$commentDate = formatDate($commentrow[6])/;

echo "<div class=\"commentbody\" id=\"$commentrow[0]\">\n
<p>$newtext</p>\n

Posted by Agent Bleu on Monday, 05.2.05 @ 03:14pm | #520

I tried installing the script, made my table in the SQL database and made the php files but whenever I put:

<?php
require('inc_rate.php')/;
getComments("1")/;
submitComments("1","$PHP_SELF")/;
>

Into a page I get "Parse error: parse error, unexpected '>' in /home/destruct/public_html/bromicacid/comment.php on line 5"

Any suggestions? This was just a try at doing this as a test so it's just a php file with that code at the top.

Posted by RVincent (http://www.destructve.com/bromicacid)on Monday, 05.2.05 @ 07:36pm | #521

<?php
require('inc_rate.php')//;
getComments("test")//;
submitComments("test","$PHP_SELF")//;
>

I changed mysql data to varchar, and tried with above "test" but it will not enter anything in the db... why?

Posted by px (www.test.com)on Friday, 05.13.05 @ 05:12pm | #533

hmmmm this looks pretty good...

Posted by she devil on Friday, 05.20.05 @ 05:10am | #538

do you have that rating script you use on this page as well? That would be convienent... I'm going to browse your site ans see :)

Posted by she devil on Friday, 05.20.05 @ 05:15am | #540

Hi, I have php/mysql and apache installed on my hom computer, how is it I create the comments table? I thought the table.sql file did that automatically but when I checked what tables where being run there was on called mysql and another called test, any ideas? cheers

-------------------------------
Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Group\Apache2\htdocs\sub\inc_rate.php on line 16
-------------------------------

Posted by sneeZer (www.limevisual.com)on Monday, 05.23.05 @ 07:08pm | #544

I would like to use you script on my website. i would like my users to be able to post comments on other users profiles on my website without having the exact same comments on every profile. Can you help me achive this with your script.

Posted by Ben (http://www.chatopia.ca)on Tuesday, 05.31.05 @ 04:40pm | #553

Nevermind I Got It I Implemented It With My Hot Or Not Script Its Sooo Coool

Posted by ben (www.chatopia,ca)on Thursday, 06.2.05 @ 06:10am | #554

i might use this script on my site.... not sure yet though

Posted by just testing (www.wantsomethinglikethisonmysite.com)on Saturday, 06.11.05 @ 04:07pm | #563

Great script, I've been looking for something like this for a while now, I've only found one other free script like it on HotScripts.com, but the link was broken. :)

I'm having a really hard time linking to inc_rate.php on a web page that's 2 folders deep. I've tried putting ../../inc_rate.php and it doesn't work, I know i could just copy the file into that directory, but I can't imagine that's the correct thing to do. Any help is greatly appriciated.

Posted by Mike (www.club-gemini.com)on Sunday, 06.12.05 @ 01:06pm | #567

If your host has it, you can use phpMyAdmin. That's what I do.

Posted by Brian Zimmer on Monday, 06.13.05 @ 05:51pm | #575

Please, Is there any way to delete or edit the comments?

Otherwise works fine!

BTW -
Looks like one '?' is missing here:

<?php
require('inc_rate.php')/;
getComments("1")/;
submitComments("1","$PHP_SELF")/;
>


Posted by Minna (http://www.minnasora.net)on Monday, 06.13.05 @ 05:51pm | #571

Re: [I}I'm having a really hard time linking to inc_rate.php on a web page that's 2 folders deep. I've tried putting ../../inc_rate.php and it doesn't work, I know i could just copy the file into that directory, but I can't imagine that's the correct thing to do. Any help is greatly appriciated.[/I]

Specify the complete path as you would access it on the server, not the site. Like on my site, I do the require(/home/sitename/public_html/inc_rate.php)

It works that way :)

Posted by Tim on Thursday, 06.23.05 @ 11:50pm | #581

This is only a test

Posted by Oliver Deocampo on Tuesday, 06.28.05 @ 02:35pm | #584

Thank you for this tutorial.

Posted by Rai on Wednesday, 06.29.05 @ 03:55am | #588

use this if u want to have buttoms to insert some bbcode

<script type="text/javascript">
<!--// Insert bbCode Script written By: willyduitt@hotmail.com
function setCaretPos(input){
if(input.createTextRange){
input.caretPos = document.selection.createRange().duplicate()/;
}
}

function insertAtCaret (input,button) {
if(document.all && input.caretPos && input.createTextRange){
if(button.value.match(/(\*)?(\w+\=\w+|\w)/i)){
var BBcode = RegExp.$2, isActive = RegExp.$1/;
if(BBcode.match(/^S$/i)){
alert('Please right click on the button and choose a '+button.value+'!')/;
return/;
}
if(BBcode.match(/^L$/i)){
var url = prompt('Please enter the URL of your link.','http://')/;
if(!input.caretPos.text){
var link = prompt('Please enter the text to display for the link.','')/;
if(link.length == 0) link = url/;
} else link = input.caretPos.text/;
input.caretPos.text = ''/;
return/;
}
if(BBcode.match(/^Q$/i)){
if(!input.caretPos.text){ BBcode = 'QUOTE' }/;
else{ input.caretPos.text = '

Quote:
'+input.caretPos.text+'
'/;
return/;
}
}
if(BBcode.match(/^C$/i)){
BBcode = 'COLOR='+button.style.color.toUpperCase()/;
}


if(input.caretPos.text.length == 0){
if(isActive) BBcode = BBcode.replace(/\=\w+$/,'')/;
input.caretPos.text = '['+isActive.replace(/\*/g,'/')+BBcode+']'/;
button.value = (button.value == button.value.replace(/\*/g,''))
? '*'+button.value.replace(/\*/g,'')
: button.value.replace(/\*/g,'')/;
}
else{ input.caretPos.text = '['+BBcode+']'+ input.caretPos.text
+ '[/'+BBcode.replace(/\=\w+$/,'')+']'/;
}
}
}
}
//-->
</script>

<?php
//create the form to submit comments
//you can add more fields, but make sure you add them to the db table and the page, submitcomment.php
echo "
<a name=\"post\">
<div id=\"submitcomment\" class=\"submitcomment\">
<form name=\"submitcomment\" method=\"post\" action=\"submitcomment.php\" onSubmit=\" return form_Validator(this)\">
<table width=\"100%\">
<tr>
<th colspan=\"2\"><h3 class=\"formtitle\">Deja tu comentario aqui</h3></th>
</tr>
<tr>

<th scope=\"row\"><p class=\"req\">Nombre:</p></th>
<td><input class=\"form\" tabindex=\"1\" id=\"name\" name=\"name\" /></td>
</tr>
<tr>
<th scope=\"row\"><p class=\"opt\">Email:</p></th>
<td><input class=\"form\" tabindex=\"2\" id=\"email\" name=\"email\" /></td>
</tr>
<tr>

<th scope=\"row\"><p class=\"opt\">URL:</p></th>
<td><input class=\"form\" tabindex=\"3\" id=\"url\" name=\"url\" /></td>
</tr>
<tr valign=\"top\">
<th scope=\"row\"><p class=\"req\">Comentario:</p><br />
<input type=\"button\" value=\"BOLD\" onclick=\"insertAtCaret(this.form.text,this)\">
<input type=\"button\" value=\"ITALIC\" onclick=\"insertAtCaret(this.form.text,this)\">
<input type=\"button\" value=\"UNDERLINE\" onclick=\"insertAtCaret(this.form.text,this)\">
<input type=\"button\" value=\"COLOR\"
style=\"color:red\"
onclick=\"insertAtCaret(this.form.text,this)\"
oncontextmenu=\"var color=prompt('What Color?','RED')/;
if(color && color.length>0){
this.style.color=color/;
insertAtCaret(this.form.text,this)}
return false\">

<input type=\"button\" value=\"SIZE\"
onclick=\"insertAtCaret(this.form.text,this)\"
oncontextmenu=\"var size=prompt('What Size (1-7)?','3')/;
if(size){
if(!isNaN(size)){
this.value='SIZE='+size/;
insertAtCaret(this.form.text,this)}
else{alert('Please choose a number between 1 & 7')}}
else{this.value='SIZE'}
return false\">

<input type=\"button\" value=\"LINK\" onclick=\"insertAtCaret(this.form.text,this)\">
<input type=\"button\" value=\"QUOTE\" onclick=\"insertAtCaret(this.form.text,this)\">

</th>
<td><textarea class=\"formtext\" tabindex=\"4\" id=\"text\" name=\"text\" onselect=\"setCaretPos(this)/;\" onclick=\"setCaretPos(this)/;\" onkeyup=\"setCaretPos(this)/;\" rows=\"10\" cols=\"50\"></textarea></td>
</tr>

<tr>
<td> /;</td>
<td><input type=\"submit\" name=\"post\" class=\"submit\" value=\"Submit Comment\" /><br />




</td>
</tr>
</table>
<input type=\"hidden\" name=\"tuturl\" value=\"$tuturl\" />
<input type=\"hidden\" name=\"tutid2\" value=\"$tutid2\" />
</form>

Posted by jaime (www.myspacepics.tk)on Wednesday, 06.29.05 @ 02:23pm | #591

just a test...

Posted by Matt (http://www.sloughflash.com)on Sunday, 07.10.05 @ 10:16pm | #609

thanks for the tutorial it was great, but i have one question: how so you change the date format from am/pm to 24h time?? thanks in advance

// Mattias

Posted by Mattias (www.spathax.frac.dk)on Monday, 07.11.05 @ 05:11pm | #610

sorry i meant how do you change not how so you change

Posted by mattias on Monday, 07.11.05 @ 05:15pm | #611

nice

Posted by lola (lola.com)on Friday, 07.15.05 @ 05:51pm | #612

What happened to the tutorial, all I see is programming a little information about it?

Posted by Matthew Bonner (http://matthewbonner.homeip.net/)on Sunday, 07.17.05 @ 09:39am | #613

a

Posted by a on Saturday, 07.23.05 @ 12:08pm | #618

Hi,

I've been looking for ages for a script like this. Very nice, thank you ‹(•¿•)›

Posted by Mutant (http://www.mutantpc.f2s.com/league/week1.php)on Thursday, 07.28.05 @ 02:14pm | #627

This is prety cool!
and

Posted by wow (url)on Tuesday, 08.2.05 @ 08:40pm | #636

how r u?

Posted by ravi on Friday, 08.5.05 @ 05:38am | #639

i like the script. but i m not programmer. and i diont know programing. but i want add comment box to my site. please guide me actualy step by step, what to do? what will be the final output file extension?

Posted by ravindra on Friday, 08.5.05 @ 06:05am | #640

allo

Posted by bastros (www.lko.com)on Thursday, 08.11.05 @ 11:36am | #647

allo

Posted by bastros (www.lko.com)on Thursday, 08.11.05 @ 11:37am | #648

Hi again!

I was wondering, if this script is protedted from sql-injections? http://www.sitepoint.com/article/sql-injection-attacks-safe


Minna

Posted by Minna (http://www.minnasora.net/)on Thursday, 08.11.05 @ 05:20pm | #650

Test

Posted by Dre on Friday, 08.12.05 @ 12:53am | #651

Woo! This is a nice code, just what I was looking for. Gave me some problems though. Nothing I couldn't get around.

If your page dosen't return, refresh and creates like 100s of post with nothing in them. Replace the slimlar code in submitcomment.php with:

"<meta http-equiv='refresh' content='2/;URL=javascript:history.back()/;'>"/;

This will return the page but the poster will have to refresh the page himself to see his comment.

Posted by Dre (www.allugic.tk)on Friday, 08.12.05 @ 01:19am | #652

This looks to be exactly what I need (or very nearly).

is there any way to add a 'challenge' to the submission process to reduce/eliminate auto spam posts? You know, one of the distorted text images that a computer can't read by a human can.

Oh, is there an easy way to include or call the script in plain HTML docs? I know with cgi scripts I can change htaccess to execute .cgi from an html page. Is this possible?

Otherwise it looks great! Thanks.

Posted by eric on Tuesday, 08.16.05 @ 08:43am | #656

The comments are stored in a mySQL database on your server. You must have one in order to use this script. To edit the comments, I use phpMyAdmin, which you can install on your server for free if your host doesn't already have it. You can download it here: http://www.phpmyadmin.net/home_page/

Posted by Brian Zimmer on Monday, 08.22.05 @ 05:15pm | #664

The comments are stored in a mySQL database on your server. You must have one in order to use this script. To edit the comments, I use phpMyAdmin, which you can install on your server for free if your host doesn't already have it. You can download it here: http://www.phpmyadmin.net/home_page/

Posted by Brian Zimmer on Monday, 08.22.05 @ 05:15pm | #665

Hey
I was wondering if there is some way that I can change this:

<?php
require('inc_rate.php')//;
getComments("1")//;
submitComments("1","$PHP_SELF")//;
>

So that it always creates a uniqe commentbox so that i don't have to do it my self by changing the number. It's mostly because I'm trying to use you script with a gallery script and i want my useres to be able to comment on every picture seperately if you understand what I meen?

what I'm trying to do is shown here: www.php2004.1go.dk/images/

btw. sorry for my poor english

Posted by Niels (php2004.1go.dk/images/)on Sunday, 09.4.05 @ 09:41am | #676

You have to make the commentid unique to each picture.

So in your case, the only thing unique to each picture is the picture name, so we can use that as the id. The picture name is sent in the URL as ?i=picturename.jpg, so to use this in php we use $i.

So, when you create your table, change the line:

'tutorialid' int(11) NOT NULL default '0',

To:

'tutorialid' varchar(64) NOT NULL,

Then change:

<?php
require('inc_rate.php')///;
getComments("1")///;
submitComments("1","$PHP_SELF")///;
>

To

<?php
require('inc_rate.php')///;
getComments($i)///;
submitComments($i,"$PHP_SELF")///;
>

Posted by Brian Zimmer on Monday, 09.5.05 @ 10:09am | #689

I am looking for the same thing, I have a profile system set up and I was wondering if I could paste some code to allow a new comment field to be set up for them. Instead of using a number system for new comments, could it be done through an ID? Also too.. was wondering how to delete comments, or even how a a member could delete it themselves.
Thanks for any input, nice script by the way!!

~Morphic

Posted by Morphic on Sunday, 09.18.05 @ 08:41pm | #688

It seems that this script loads new comments at the bottom, is there anyway to reverse it? Making the new comments appear first at the top?

Posted by Josh on Friday, 09.30.05 @ 11:50pm | #696

Very good comment script! I like it

Posted by Zach (http://www.ultimatethrillzone.com)on Saturday, 10.1.05 @ 06:49pm | #697

Sorry I should've read the WHOLE tutorial.. found it, thanks!

Posted by Josh on Thursday, 10.6.05 @ 12:25pm | #701

i installed apache2triad, added the database in mysql with phpmysql,,,,changed in inc_rate.php and testpage.php the 4 settings (hostname,username,pass,name) and placed them in the root my server.
the testpage loads normaly, but now when i want add a comment and press the submit button it just returns to the same site without showing the content of the types message.
what i am doing wrong?

look for an example
http://kyrylivka.mine.nu/testpage.php

Posted by Gillis on Thursday, 10.20.05 @ 12:45pm | #705

I have a problem, it wants to redeclare the bbcode if i put multiple comments comment in 1 page

i want to add 1 or more "add comment" codes in 1 page, but im getting this error if i put more then 1 in it....

how do i fix it?

Fatal error: Cannot redeclare bbcode() (previously declared in /home/www/***************/inc_rate.php:144

Posted by revelation on Saturday, 10.22.05 @ 06:38am | #706

Very nice, what are the security features of this script?

Posted by Krayis on Sunday, 11.27.05 @ 01:36am | #734

Very nice, what are the security features of this script?

Posted by Krayis on Sunday, 11.27.05 @ 01:37am | #735

good service

Posted by Frank Johnson (http://www.none.com)on Tuesday, 12.6.05 @ 03:04am | #739

greetings there - great script it is pretty much what i have been looking for. i did, however, have a few questions/issues i wanted to know if there way a way around them :)

*someone up top asked this:

<i>basically, I want to display in groups of 10. How do I do this? Do I have to manually create a new page every time it hits 10 or is there a way for it to automatically create a page such hat when I hit 11 comments, the first one automatically goes to the 2nd page and so on (and when it hits 21, the 1st comment goes to 3rd page, next ten on 2nd page, last 10 on first page, etc). Also, once I do that, how would I call each page?</i>

and i cannot seem to find if you replied with an answer. if the answer is no that's fine but if there is a way to automatically create a new page after 5 comments or so that would rule

also - is there a way to have the comments script and the 'comment here' script on differnet pages?

thanks

cloei

Posted by cloei (http://www.riotdorque.net)on Wednesday, 12.7.05 @ 05:00am | #740

<b>Test
<i>Test
http://www.bedpan.ca

Woo...

Posted by JMan (http://www.bedpan.ca)on Friday, 12.9.05 @ 11:36am | #741

<b>Test</b>
<i>Test</i>
<u>Test</u>
Agh, ignore that. =)

Pretty nice code, althought it's very long.

Posted by Someone you don't want to know. (www.elementalflash.com)on Saturday, 12.10.05 @ 08:23am | #742

Is it possible to set the 'number' in

<?php
require('inc_rate.php')/;
getComments("1")/;
submitComments("1","$PHP_SELF")/;
?>

to the 'id' of my mysql table so that I don't have to edit this by hand?

How would i do that?

Posted by W1lly on Saturday, 12.10.05 @ 08:48am | #743

I like this script. Quite useful!

Posted by RabidMonkey (http://www.rabid-monkey.com)on Sunday, 12.11.05 @ 05:11am | #744

My server is in a different time zone than the readers of my website are. How can I add six hours to the time of a comment in this script?

Posted by Peter (www.pattayafamily.com)on Friday, 12.16.05 @ 12:25am | #749

How do I find out the name of the database?

Posted by Scott on Friday, 12.16.05 @ 02:39pm | #750

this tutorial has helped me alot :)

Posted by tom (www.templatemadness.co.uk)on Saturday, 12.17.05 @ 12:22pm | #752

I was wondering if there is a way to get the "posted by _____ etc.." info above the comment instead of below it?

thanks

Posted by Scott on Monday, 12.19.05 @ 02:50pm | #754

Hello,

I am using html based php.
I cannot get the "submit form" do its job.
It won't submit anything..

help.

Posted by Macka 2.0 (allthesmallthings.fil.ph)on Monday, 12.26.05 @ 07:53pm | #762

YOU'RE A GOD!
YOU OWN ME!

OMG!! :)

Posted by Macka 2.0 (allthesmallthings.fil.ph)on Friday, 12.30.05 @ 07:19pm | #767

Helped ALOT!! THX!!

Posted by MsM on Thursday, 01.5.06 @ 10:10pm | #772

Love the script,

Can anyone be of some assistance and guide me in the right dircetion to do the following/;

Add an additional field such as comments #1 and comments #2 for example, much appreciated for any guidance you can offer.

Posted by Jackrabbit on Thursday, 01.12.06 @ 09:31pm | #779

Nice tutorial

Posted by Xeon on Saturday, 01.14.06 @ 07:35pm | #782

HTML and Javascript is disabled for security reasons. BBCode is used instead for formatting.

Posted by Brian on Sunday, 01.15.06 @ 06:07am | #2233

Thnakyou so uch for making this tutorial, it's great and actually works, unlike nearly every other comment tutorial.

Posted by Jamie (http://www.hotsnow.co.uk/school/)on Sunday, 01.15.06 @ 10:10am | #786

nice tutorial

Posted by ripix (http://phase02.org)on Saturday, 01.21.06 @ 09:14am | #797

after I've submitted the comment, I'm not redirected back to previous page but submitcomment.php reloads every 2 seconds

Posted by elfrosto (www.burgerbeer.org)on Thursday, 01.26.06 @ 11:07am | #802

after I've submitted the comment, I'm not redirected back to previous page but submitcomment.php reloads every 2 seconds

Posted by elfrosto (www.burgerbeer.org)on Thursday, 01.26.06 @ 11:10am | #803

In which file do I create the SQL database? Thanks

Posted by Daymond (www.divinedesignsbyd.com)on Wednesday, 02.1.06 @ 08:46am | #810

Just Chekin. Can't seen to get it to work

Posted by Bryant on Tuesday, 02.7.06 @ 02:34am | #817

the redirection part doesn`t work...it redirects me to the same page :| (submitcomment.php)

nice script. tnx

Posted by x on Tuesday, 02.7.06 @ 04:20pm | #820

Well...i have one question...how can I make the script start a new page every 10 (example) posts?

I hope you understand what I want.

tnx for the script

Posted by DotCom on Tuesday, 02.7.06 @ 05:55pm | #821

Wow. This is cool.

Posted by Yves on Thursday, 02.9.06 @ 04:19pm | #829

Great script! Just what i was looking for, Thanks!

I did however add some code to submitcomment.php to mail me whenever someone leaves a comment and it tells me also on which page the comment was written. Saves a lot of time and energy if you use the script on multiple pages. /;-)

$MailToAddress = "something@yourdomain.com"/;
$MailSubject = "comment on $tuturl"/;
$Message = "$name wrote: \n\n $message \n\n on http://www.yourdomain.com$tuturl"/;


if (!is_array($HTTP_POST_VARS))
return/;
reset($HTTP_POST_VARS)/;
while(list($key, $val) = each($HTTP_POST_VARS)) {
$GLOBALS[$key] = $val/;
$val=stripslashes($val)/;


}
mail( "$MailToAddress", "$MailSubject", "$Message", "From: $email")/;

Posted by Dorine (http://www.allemaalkatten.nl)on Wednesday, 02.15.06 @ 04:01pm | #849

Can you make an Admin.php that we can edit or delet some comment

Posted by tony on Friday, 02.17.06 @ 03:27am | #852

sweet ima try it out.

Posted by Reeve (http://stevents.net)on Sunday, 02.19.06 @ 10:38pm | #854

sweet ima try it out.

Posted by Reeve (http://stevents.net)on Sunday, 02.19.06 @ 10:41pm | #856

Where is the "e-mail" information going ???

Posted by Adam on Friday, 03.3.06 @ 06:09pm | #881

Ok nevermind ! stupid question ! :S

Posted by Adam on Friday, 03.3.06 @ 06:10pm | #882

Hi,
how do i make the text "posted by..." Smaller than the rest of the text ???

I tried adding H6,H7 or ++ in

//create the right date format
$commentDate = formatDate($commentrow[6])/;

echo "<div class=\"commentbody\" id=\"$commentrow[0]\">\n
<p>$commentbb</p>\n
<h6 p class=\"postedby\">Posté par "/;
if($commentrow[3]){
echo "<a href=\"$commentrow[3]\">$commentrow[2]</a> "/;
} else {
echo "$commentrow[2] "/;
}
echo "le $commentDate | #$commentrow[0]</h6></p>\n
\n</div>"/;

}
echo "</div>"/;
}




And it didn't work and i don't know what to do else..
Thanks !

Posted by Adam on Friday, 03.3.06 @ 08:28pm | #883

Nice Tutorial...

Posted by Nick (www.qindustries.co.nr)on Wednesday, 03.8.06 @ 05:29am | #892

I LOVE THIS COMMENT SYSTEM!!! You're the best!

Posted by .albino (http://zerodesignz.net)on Wednesday, 03.15.06 @ 11:28am | #909

This looks like something I could use.

Posted by Sammy Snead on Friday, 03.24.06 @ 11:10pm | #930

i have a few questions...firstly i keep getting sent to the 'Submission Successful' page, but then it doesnt return me to the previous page, it just keeps on trying to over and over, but nothing happens.
Secondly, how can i make it so the table is centred on the page instead of hard up against the left edge?

Thanks for your help, awesome script by the way

Posted by Andrew (http://www.teejunctiononline.com)on Monday, 03.27.06 @ 10:37am | #936

To get back the site with the last comment visible just change the:

if($sendcomment){
//header("Location: $tuturl")/;
echo "<h1>Submission Successful</h1>"/;
echo "Your comment has been submitted. You will now be redirected back to the last page you visited. Thanks!"/;
echo "<meta http-equiv='refresh' content='2/;URL=$tuturl'>"/;
} else {
echo "There was an error with the submission. "/;
}

into:
if($sendcomment){
header("Location: {$_SERVER['HTTP_REFERER']}")/;
} else {
echo "There was an error with the submission. "/;
}

And that's it. I hope it helps someone else:)

Posted by someone on Monday, 04.10.06 @ 05:37am | #967

Greetings. The script seems very nice and it is well explained.
I would like to add it to my website to make easy for visitors to post comments on articles (who are stored in a table "articles" and located by the field "id_article").
You are actually using a "page number" (e.g. 22), where can i, or do i have, to call/insert that value ?

do i have to modify

<?php
require('inc_rate.php')/;
getComments("1")/;
submitComments("1","$PHP_SELF")/;
?>

by

<?php
require('inc_rate.php')/;
getComments("id_article")/;
submitComments("id_article","$PHP_SELF")/;
?>

in submitcomment.php
to i have to connect to my table "articles" and get "$id-article"?
but where in "getcomment" function? :)

i suppose i can also try to add an id_article field in your table and cross it with "my" table (but how :)

Sorry for my english and congratulations for your job!!! /;-)

Posted by Laurent (http://www.atemporel.com)on Wednesday, 04.12.06 @ 04:29am | #972

test@ hi there?!

Posted by test (test)on Monday, 04.17.06 @ 08:36am | #984

test@ hi there?!

Posted by test (test)on Monday, 04.17.06 @ 08:50am | #985

i wanna make the pagenuber set by profilenumber how do i do this? the variable is i think "$smarty.get.id" but not sure but can find out later the question is can i use a variable on the id?
looks great and is there a adminsection?

greetzzz Edwin

Posted by Edwin on Saturday, 04.22.06 @ 10:36am | #997

this script looks easy to configure. the only problem i have with this is that the comment number seems to be including the count for post from other threads/pages.

does anybody know how to fix this?

echo "on $commentDate | #$commentrow[0]</p>\n

Posted by boy_bastos on Sunday, 04.23.06 @ 05:17am | #999

checking out duplicate posts would be nice too. oh well.

Posted by boy_bastos on Sunday, 04.23.06 @ 05:20am | #1001

heh, trawling server logs, glad to see my bbcode script still being used ... that was one of my first ever php scripts I wrote to teach myself php!

GL!

Posted by Duncan Mundell on Tuesday, 04.25.06 @ 09:25pm | #1007

heh, trawling server logs, glad to see my bbcode script still being used ... that was one of my first ever php scripts I wrote to teach myself php!

GL!

Posted by Duncan Mundell on Tuesday, 04.25.06 @ 09:25pm | #1008

i'm having trouble!! i loved your tutorial! but i cant get the page to post in the database!

i really need help! if anyone can help me please do!

i think it postes but only the commentid, the toturialid and the date, the rest doenst apear!

please help me! mingos.mufassa@gmail.com is my emai!

tanks everyone

Posted by Omega on Tuesday, 04.25.06 @ 11:34pm | #1009

great script!
Have one question, is it possible to set a limit for how many entries it should be on a page??

so it automaticly makes several pages if I have that many comments.

gustaf.gillander@gmail.com
thanks in advance

Posted by Jegarn (http://lux.blg.edu.stockholm.se/~gugil001/gruppsida/)on Tuesday, 05.9.06 @ 12:17pm | #1039

One thing more.
How to I get those cubes in front of Posted by..... in the bottom

Posted by Jegarn (http://lux.blg.edu.stockholm.se/~gugil001/gruppsida/)on Tuesday, 05.9.06 @ 12:19pm | #1040

Great!

10x 4 posting it

And2

Posted by And2 on Wednesday, 05.17.06 @ 01:48pm | #1054

nice script. very very nice.

Posted by robert on Friday, 05.26.06 @ 04:35pm | #1147

For anyone who might be interested...

I downloaded this script a few months earlier for use on my website and i am using it on multiple pages. Due to the overwhelming succes of this script on my pages i had to addept the script to my needs and in the mean time i have modified the script so that:

1. When a new comment has been placed the admin receives a mail containing the comment and the url to the page.
2. There is a possibility to respond to the comments on the page or by mail if the email was filled.
3. If the commenter filled in the emailaddress, they get an email if someone reponds to their comment.
4. I included a paginator script that limits the entries on a page and
5. I have almost completed creating an admin section for editing or deleting comments.

Not bad for a newbie in php don't you think?

If you would like to see how it works on my site take a look at the bottom of this page > http://allemaalkatten.nl/verzorging/drachtig.html

Posted by Dorine Post (http://allemaalkatten.nl)on Wednesday, 05.31.06 @ 12:30pm | #1326

Hm... i cant get it to work.. but i dont think i have my mysql database configed correctly

Posted by Michael Czigler (http://sbb.us.to)on Friday, 06.2.06 @ 09:42pm | #1415

can someone tell me why this isn/;t working...

<?php

//Connect to the database
$connection = mysql_connect ( "localhost", "myusername", "mypassword" )/;

$sql = 'CREATE TABLE `comments` (
`commentid` int(11) NOT NULL auto_increment,
`tutorialid` int(11) NOT NULL default '0',
`name` text NOT NULL,
`url` text NOT NULL,
`comment` text NOT NULL,
`email` text NOT NULL,
`date` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`commentid`),
KEY `tutorialid` (`tutorialid`)
)'/;
echo 'Creating table: \'zones\'....'/;
mysql_query( $sql, $conn )/;

?>

Posted by Mike on Saturday, 06.3.06 @ 12:59am | #1421

Thanks for the script it is just what I was looking for!

Works great.

Posted by jmartellpro on Monday, 06.12.06 @ 07:55pm | #1906

It's showing the wrong date and time. How can I solve this problem? It's showing the year as 2007 and the time is out by 4 hours.

Seems to be something to do with the now() function?

Posted by James on Sunday, 06.18.06 @ 12:59am | #2063

I've sorted it, it was something I'd done with the code. Had changed the mktime() day and month around instead of the code before it, to show the more normal day, month, year. Yanks are so odd with their month, day, year business.

Posted by James on Sunday, 06.18.06 @ 03:55am | #2070

HELP
I uploaded games.php (the page where I want the comment box to appear), inc_rate.php, submitcomment.php and table.sql into the same directory. But when I opened my page, the showed up:

Table 'osforum.comments' doesn't exist

help please

Posted by jingquan (http://www.orandysoftware.com)on Saturday, 07.8.06 @ 07:06am | #2246

How do I change the font size. Many thanks in advance.

Posted by bamy on Saturday, 07.8.06 @ 08:09am | #2247

Nice tutorial

Posted by GG on Tuesday, 07.18.06 @ 10:05pm | #2309

Genius small fast and simple script.
Easy to edit PHP, so it goes anywhere

Posted by Critic (http://www.charlottecritic.com)on Wednesday, 08.2.06 @ 12:28pm | #2559

Wonderful script, works like a charm except for the bit that should return back to the original page after a comment has been submitted. I found three solutions in the comments here but none of them seem to work. Can anybody shed any light on this?

Thanks in advance.

Posted by Verian on Thursday, 08.3.06 @ 02:38pm | #2560

Hi!
There is a problem with the url system...When I type in the url and submit my comment the auto-linking system does this:
http://mywebsiteaddress/somefolder/the_submited_url
Why is this happening?
Please reply

Posted by vlad230 (www.auto-tuning.fusionxhost.com)on Sunday, 08.6.06 @ 01:50pm | #2562

testing html <img src"http://www.anothernightout.com/chemofluxxe/pic1b.jpg">

Posted by macky (does this allow html inside comments?)on Saturday, 08.12.06 @ 03:04pm | #2566

testing html <img src="http://www.anothernightout.com/chemofluxxe/pic1b.jpg">

Posted by macky (does this allow html inside comments?)on Saturday, 08.12.06 @ 03:05pm | #2567

thanks man

Posted by fadi on Wednesday, 08.16.06 @ 08:23am | #2572

thanks man

Posted by fadi on Wednesday, 08.16.06 @ 08:24am | #2573

People are still using this?

Should be blank line above

thanks

Posted by b (www.a.com)on Sunday, 08.20.06 @ 08:32pm | #2575

coooooool


[URL="http://www.google.com"]google[/URL]

Posted by jem on Wednesday, 08.23.06 @ 02:34am | #2581

rshdyjtfgsbyjdghjjhjhj

Posted by ddh (dhhhdhfgh)on Friday, 09.8.06 @ 08:47am | #2590

test

Posted by test on Thursday, 09.14.06 @ 09:02am | #2592

nice script

Posted by test on Sunday, 09.17.06 @ 11:36am | #2596

nice script

Posted by test on Sunday, 09.17.06 @ 12:05pm | #2597

hidsfsdfsdf

Posted by falih on Sunday, 09.24.06 @ 02:49am | #2601

www.google.com

or

http://www.google.com

Posted by Tester on Sunday, 09.24.06 @ 06:17am | #2602

hillo

Posted by boo on Sunday, 09.24.06 @ 06:45am | #2603

Nice Script :)

Posted by DarkAngelBv (http://www.darkangelbv.iad.ro)on Monday, 09.25.06 @ 10:16am | #2604

Very nice script

Posted by Buddy on Wednesday, 09.27.06 @ 09:16am | #2605

Very nice script

Posted by Buddy on Wednesday, 09.27.06 @ 09:16am | #2606

yea

Posted by keith on Wednesday, 10.4.06 @ 08:59am | #2609

Looking for a simple script for our newest site. tHis might just be it.

Posted by CoffeeTimer (http://www.alaskastudentloan.net)on Thursday, 10.5.06 @ 10:36am | #2610

thanks

Posted by John Mayer (svrclanrip.tripod.com)on Saturday, 10.7.06 @ 02:00pm | #2612

thanks

Posted by John Mayer (svrclanrip.tripod.com)on Saturday, 10.7.06 @ 02:00pm | #2613

thanks

Posted by John Mayer (svrclanrip.tripod.com)on Saturday, 10.7.06 @ 02:00pm | #2614

thanks

Posted by John Mayer (svrclanrip.tripod.com)on Saturday, 10.7.06 @ 02:00pm | #2615

thanks

Posted by John Mayer (svrclanrip.tripod.com)on Saturday, 10.7.06 @ 02:00pm | #2616

thanks

Posted by John Mayer (svrclanrip.tripod.com)on Saturday, 10.7.06 @ 02:00pm | #2617

thanks

Posted by John Mayer (svrclanrip.tripod.com)on Saturday, 10.7.06 @ 02:00pm | #2618

I got everything to work, but when I try submitting a comment, I get:

There was an error with the submission.

Anyway to fix this?

Posted by Rodrigo (www.bioviral.net)on Saturday, 10.7.06 @ 05:14pm | #2619

testing did'nt.

Posted by test on Sunday, 10.8.06 @ 08:35am | #2620

I've lost all respect for you. You are a very sick, sick boy. Don't ever talk to me anymore.

Posted by mandy on Sunday, 10.8.06 @ 08:44am | #2621

I need help I can't put single quotation marks between letters such as "Don't" or "I've". It returns error "There was an error with the submission." What seems to be the problem?

Posted by Daniel on Sunday, 10.8.06 @ 09:42am | #2622

I just wanted to say a HUGE thank you for the most usefull tutorial!!!

Posted by michel (http://www.michelvanessen.com)on Monday, 10.9.06 @ 03:24pm | #2623

hi there i testing this script it seems to be useful but what i wonder is how to change date format eg delete the day name

Posted by alibaba on Thursday, 10.12.06 @ 06:16am | #2626

This could be what I'm after...

Posted by bert schneider (www.makesaracket.com)on Friday, 10.13.06 @ 07:22am | #2627

hey i got a user system how do i make it so they have to be an user to make a comment

Posted by darkclaw on Wednesday, 10.18.06 @ 07:09pm | #2629

Awesome script. I got it working on the first try.

I even tweaked the comment ID to match the video/photo ID on my site.

Im totaly over the moon!!

Thank you for sharing such a simple easy tutorial.

Posted by Kerry (http://www.ringaroot.com)on Wednesday, 10.25.06 @ 06:57am | #2637

Excellent tutorial, working first time, looking great! thx

Posted by Dave (http://www.creative-networks.org)on Friday, 10.27.06 @ 11:39am | #2640

hey, thanks so much for this script!!!!! its been a life saver!

Posted by Jonescy73 (www.yeshuagirl.com)on Monday, 10.30.06 @ 01:13pm | #2644

Hey, I am having a problem.

It doesn't redirect back to the original page. Was there anywhere that we were supposed to specify where our original page is located?

Posted by Travis Doerr on Wednesday, 11.1.06 @ 05:32pm | #2646

Incredible Script!

Works perfectly on my website. I'm gonna put this on digg.

Thanks for the script. I have been looking for something like this for a long time.

Posted by Manhas (www.wizardsbuzz.com)on Monday, 11.6.06 @ 03:02pm | #2648

great script...i was able to install it...but it just it doesn't redirect me to the page where i posted...it just keeps reloading...what do i do?

Posted by booster on Saturday, 11.11.06 @ 08:21am | #2658

This is a great script and will work excellent for my new video gaming section!
For all you noobies that are confused with this, heres a breakdown on how to create the MYSQL database:
1. You need to have a site that supports php and mysql. No questions asked. This will not work with shtml, asp, or any other kind of ssi include because you need a DATABASE!!!!

2. If you have a site that supports php and mysql, first you need to create a user and a database. If you are on a real site with a C-PANEL, this is easy. Click on MYSQL databases. Go to the bottom of the list. Create a user. Call it whatever you want, preferably the begginging of it with the name of your username you log into your cpanel with. Mine looked like this: kumitek_user. You put your username to log into the c-panel with: ex. kumitek. Then an underscore: ex. kumitek_. Next, make up any name you want that isn't being used in your database: kumitek_user

3. Once you have your user, hit create and then it will say user created. Go back to the next page, and go to create database. Use the same step for making a database, with the username underscore and then choose a different name for your comment database. Example: kumitek_comments

3. Next, you need to add the user to the database. Go to the "add user to database" section in your mysql database page. Look on the list for the user created before, and then add it to the database you just made with ALL PRIVALEGES check. Then hit add user. You user will now be added to the database.

4. After you have made a user and database, you will now have to configure your database. On you MSQL database main page, scroll to the very bottom of the page. You should see a link called "PHP My admin"