Simple Comment System - RMB Scripting
You appear not to have an account with us, Click HERE to register an account...
RMB Scripting
Navigation
  Home
  Contact
  FAQ
  Forum
  Topsites
  Members
  Affiliates
  Arcade <-- New!
  IoxHost
Downloads
  Templates
  Scripts
  Fonts
  Image Sets
  Software
  Other
 
Tutorials
  .htaccess
  Photoshop
  C/C++
  CSS
  Macromedia Flash
  MySQL
  PHP
  PHP - User System
  HTML
  Javascript
  Macintosh
  Macromedia Fireworks
  Visual Basic
  Visual C#
  Windows
  Python
  Other
 
Latest Tutorials
RMB User Commenting Sy...
Easy Navigation Integr...
Decorate Basic Icon
paragraph shortner
Convert Email address ...
Latest Comments
Badge System
Pet system
Pet system
Badge System
Report & Warn Script
Stats
Total Members: 597 [241]
Total Tutorials: 284
Newsest User: andrerds
Todays Unique Hits: 116
Users Online: 0
 
7 Guests
Poll
What do you look for in a web host?
Price
Uptime
Reviews
Customer Service
Size of Company
Main Content
Tutorial: Simple Comment System By jambomb
Hey i suppose this is my second tutorial but first got deleted as site crashed,

I'll show you how to create a simple comment system.

Here is the sql for the members comments to go in just simply paste in a SQl in your database.

   
CODE:


CREATE TABLE IF NOT EXISTS `members_comments` (
`id` int(11) NOT NULL auto_increment,
`member_id` int(11) NOT NULL,
`from_id` int(11) NOT NULL,
`content` varchar(250) NOT NULL,
`time` int(11) default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=15 ;



Now for the main part, on your members.php page just simply paste this code on the page where you would like to see the comments.

   
PHP:


<table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td align="center" class="style1">Comments</td>
                  </tr>
                  <tr>
                    <td align="center">
                    <?php
                    
                    
// if not logged in then show you cant post a comment.
                    
if(!$logged['member_id']){
                    echo 
"You need to be logged in to post a comment! <a href='index.php'>Login Here!</a>";
                    }
                    
// else if you are logged in then show the link.
                    
else{
                    echo 
"<a href=\"comment_post.php?user=$user[id]\">Post a Comment!</a>";
                    }
                    
?></td>
                  </tr>
                  <tr>
                    <td align="left">
                    <?php
                    
                    
// Includes the config file
                    
include "config.php";
                    
                    
// Getting the comments
                    
$get_comments mysql_query("SELECT * FROM `members_comments` WHERE `id` = '$user[id]' ORDER BY `id` DESC LIMIT 20"); 
                    
$row mysql_num_rows($get_comments);
                    
$fetch_comments mysql_fetch_array($get_comments);
                    
                    
// Checking if there is comments if not saying there are no comments. =]
                    
if($row == "0"&& $fetch_comments['id'] == $logged['id']){
                    echo 
"<center>You have no comments at the moment!</center>";
                    }
                    elseif(
$row == "0"){
                    echo 
"<center>$user[username] has no comments at the moment!</center>";
                    }
                    else{
                    
// Displaying all the comments now.
                    
while ($comments mysql_fetch_array($get_comments))
                    {
                    
// Getting the users information
                    
$get_member mysql_query("SELECT * FROM `members` WHERE `id` = '$comments[from_id]'");
                    
$member mysql_fetch_array($get_member);
                    echo 
"<table width=\"100%\" border=\"0\" cellspacing=\"3\" cellpadding=\"0\">
                            <tr>
                                <td rowspan=\"2\" width='100'><a href=\"?user=
$member[username]\"<img src='$member[avatar]' height='100' width='100' /></a></td>
                                <td class='links'><a href=\"?user=
$member[username]\">$member[username]</a>";
                    
// Showing how long the comment was posted!
                    
$time time() - $comments['time'];
                    
$in "seconds";
                    if(
$time >= 60)
                    {
                    
$time = (int) ($time/60);
                    
$in "minute(s)";
                    }
                    if(
$time >= 60)
                    {
                    
$time = (int) ($time/60);
                    
$in "hours";
                    if(
$time >= 24)
                    {
                    
$time = (int) ($time/24);
                    
$in "days";
                    }
                    }
                    
// If the logged in user then display a reply link.
                    
if($logged['id'] == $user['id']){
                    echo 
" - $time $in ago - <a href=\"comment_reply.php?user=$comments[from_id]\">Reply!</a>";
                    }
                    
// if not then dont dispay a reply link.
                    
else{
                    echo 
" - $time $in ago";
                    }
                    echo 
"</td>
                            </tr>
                            <tr>
                                <td>
$comments[content]</td>
                            </tr>
                          </table>"
;
                    }
                    }
                    
                    
?>



Here is the php for the Comment Post, Just create a page called comment_post.php and put this code in

   
PHP:

                    <?php
                    
                    
// Includes the config file
                    
include "config.php";
                    
                    
// Check if logged in or not.
                    
if(!$logged['id']){
                    echo 
"You need to be logged in to post a comment! <a href='index.php'>Login Here!</a>";
                    }
                    
// Check if the comment was posted if not show the comment form.
                    
elseif($_POST['message'] AND $_POST['user']){
                    
$message mysql_real_escape_string($_POST['message']);
                    
$to $_POST['user'];
                    
mysql_query("INSERT INTO `members_comments` VALUES ('','$to','$logged[id]','$message',unix_timestamp())");
                    
                    echo 
"Comment Posted.";
                    
                    }
                    else{
                    
                    
$get_member mysql_query("SELECT * FROM `members` WHERE `id` = '$_GET[user]'");
                    
$member mysql_fetch_array($get_member);
                    
                    if(!
mysql_num_rows($get_member)) {
                    echo 
"This member does not exist! <a href='members.php?user=$_POST[user]'>Back</a>";
                    }
                    else{
                    
$member mysql_fetch_array($member);
                    echo 
"
                    Adding a comment to 
$member['username]'s profile!
                    <form action='comment_post.php?user=
$member[id]' method='POST'>
                    <input type='hidden' name='user' value='
$_GET[user]'>
                    Comment: <input type='text' name='message'>
                    <input type='submit' value='Add'>
                    </form>"
;
                    }
                    }
                    
                    
                    
?>




Now for the comment reply. Call this page comment_reply.php and put the following code in the page.

   
PHP:


                    <?php
                    
                    
// Includes the config file
                    
include "config.php";
                    
                    
// Check if logged in or not.
                    
if(!$logged['id']){
                    echo 
"You need to be logged in to post a comment! <a href='index.php'>Login Here!</a>";
                    }
                    
// Check if the comment was posted if not show the comment form.
                    
elseif($_POST['message'] AND $_POST['user']){
                    
$message mysql_real_escape_string($_POST['message']);
                    
$to $_POST['user'];
                    
mysql_query("INSERT INTO `members_comments` VALUES ('','$logged[id]','$to','$message',unix_timestamp())");
                    
                    echo 
"Comment Posted.";
                    
                    }
                    else{
                    
                    
$get_member mysql_query("SELECT * FROM `members` WHERE `id` = '$_GET[user]'");
                    
$member mysql_fetch_array($get_member);
                    
                    if(!
mysql_num_rows($get_member)) {
                    echo 
"This member does not exist! <a href='members.php?user=$_POST[user]'>Back</a>";
                    }
                    else{
                    
$member mysql_fetch_array($member);
                    echo 
"
                    Adding a comment to 
$members['username]'s profile!
                    <form action='comment_reply.php?user=
$member[id]' method='POST'>
                    <input type='hidden' name='user' value='
$_GET[user]'>
                    Comment: <input type='text' name='message'>
                    <input type='submit' value='Add'>
                    </form>"
;
                    }
                    }
                    
                    
                    
?>



There you go, should all work fine.

Comment below or email me if there are only problems.

Thanks - www.ViteTech.net

Difficulty: Easy
Views: 1375
Rating:
Comments
Posted on Saturday 4th April 2009 at 02:48 PM
sean04
when i click post a comment i get this error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\Software\Xampp\htdocs\midoun_01\comment_post.php on line 28

line 28 says

$member = mysql_fetch_array($member);

any ideas?
Posted on Saturday 4th April 2009 at 03:11 PM
ShadowMage
whats line 27?
Posted on Saturday 4th April 2009 at 05:02 PM
setsukemizuhara
line 27 is a }
and its calling an already done mysql_fetch_array().

take out the $member = mysql_fetch_array($member);
Posted on Saturday 4th April 2009 at 09:20 PM
ShadowMage
Shouldn't be.

Sometimes people declare a variable twice. once as a query the other as the fetch array.
Posted on Sunday 5th April 2009 at 05:23 PM
sean04
thanks. that got rid of the error.

the only problem is is that it doesn't post... it says it does but it doesn't???
Posted on Tuesday 7th April 2009 at 11:34 PM
setsukemizuhara
Does it goes through a refresh and stuff or what?
Posted on Wednesday 8th April 2009 at 07:18 AM
sean04
well i refresh it myself to see if it worked but it just didn't post to begin with
Posted on Wednesday 8th April 2009 at 08:33 AM
Dean
$member = mysql_fetch_array($member);

replace wiht

$member = mysql_fetch_array($get_member);
Posted on Wednesday 8th April 2009 at 04:11 PM
sean04
thanks dean but the data doesn't even go into the database.
Posted on Saturday 17th July 2010 at 11:07 PM
iSPLAZE
THIS PART DONT WORK ! THE PART U PUT ON MEMBERS.PHP

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" class="style1">Comments</td>
</tr>
<tr>
<td align="center">
<?php

// if not logged in then show you cant post a comment.
if(!$logged['member_id']){
echo "You need to be logged in to post a comment! <a href='index.php'>Login Here!</a>";
}
// else if you are logged in then show the link.
else{
echo "<a href=\"comment_post.php?user=$user[id]\">Post a Comment!</a>";
}
?></td>
</tr>
<tr>
<td align="left">
<?php

// Includes the config file
include "config.php";

// Getting the comments
$get_comments = mysql_query("SELECT * FROM `members_comments` WHERE `id` = '$user[id]' ORDER BY `id` DESC LIMIT 20");
$row = mysql_num_rows($get_comments);
$fetch_comments = mysql_fetch_array($get_comments);

// Checking if there is comments if not saying there are no comments. =]
if($row == "0"&& $fetch_comments['id'] == $logged['id']){
echo "<center>You have no comments at the moment!</center>";
}
elseif($row == "0"){
echo "<center>$user[username] has no comments at the moment!</center>";
}
else{
// Displaying all the comments now.
while ($comments = mysql_fetch_array($get_comments))
{
// Getting the users information
$get_member = mysql_query("SELECT * FROM `members` WHERE `id` = '$comments[from_id]'");
$member = mysql_fetch_array($get_member);
echo "<table width=\"100%\" border=\"0\" cellspacing=\"3\" cellpadding=\"0\">
<tr>
<td rowspan=\"2\" width='100'><a href=\"?user=$member[username]\"<img src='$member[avatar]' height='100' width='100' /></a></td>
<td class='links'><a href=\"?user=$member[username]\">$member[username]</a>";
// Showing how long the comment was posted!
$time = time() - $comments['time'];
$in = "seconds";
if($time >= 60)
{
$time = (int) ($time/60);
$in = "minute(s)";
}
if($time >= 60)
{
$time = (int) ($time/60);
$in = "hours";
if($time >= 24)
{
$time = (int) ($time/24);
$in = "days";
}
}
// If the logged in user then display a reply link.
if($logged['id'] == $user['id']){
echo " - $time $in ago - <a href=\"comment_reply.php?user=$comments[from_id]\">Reply!</a>";
}
// if not then dont dispay a reply link.
else{
echo " - $time $in ago";
}
echo "</td>
</tr>
<tr>
<td>$comments[content]</td>
</tr>
</table>";
}
}

?>

ABUNCH OF ERRORS
Post A Comment
1 2
Notice:
Remember to post long codes on our pastbin! - (http://rmb.pastebin.com/)
Add Comment
You must be logged in to post a comment.
Good Evening Guest
Username: 
Password: 
Remember Username
Links
RMB Arcade
$2.50 Resellers
Free Domains
Free Games
Affiliates