Comment System with jQuery, Ajax and PHP (Version 2.0).
Wall Script
Wall Script
Tuesday, September 15, 2009

Comment System with jQuery, Ajax and PHP (Version 2.0).

Three months back I had posted an popular article Comment system with jQuery, Ajax and PHP.. Most of the readers commented about displaying existing(old) comments and database design. So in this post I had updated the old code.

Comment System with  jQuery, Ajax and PHP (Version 2.0).

Download Script     Live Demo

Database Design
Relationship between posts and comments table.
//Posts Table
CREATE TABLE posts
(
post_id INT PRIMARY KEY AUTO_INCREMENT,
post_title VARCHAR(200),
post_dis TEXT
);

//Comments Table
CREATE TABLE comments
(
com_id INT PRIMARY KEY AUTO_INCREMENT,
com_name VARCHAR(100),
com_email VARCHAR(100),
com_dis TEXT,
post_id_fk INT,
FOREIGN KEY(post_id_fk) REFERENCES posts(post_id)
);




javascript code.
Contains javascript.
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" >
$(function() {
$(".submit").click(function()
{
var name = $("#name").val();
var email = $("#email").val();
var comment = $("#comment").val();
var post_id = $("#post").val();
var dataString = 'name='+ name + '&email=' + email + '&comment=' + comment+ '&post_id=' + post_id;
if(name=='' || email=='' || comment=='')
{
alert('Please Give Valid Details');
}
else
{
$("#flash").show();
$("#flash").fadeIn(400).html('<img src="ajax-loader.gif" />Loading Comment...');
$.ajax({
type: "POST",
url: "commentajax.php",
data: dataString,
cache: false,
success: function(html){
$("ol#update").append(html);
$("ol#update li:last").fadeIn("slow");
$("#flash").hide();
}
});
}return false;
}); });
</script>

comment.php
Contains HTML code here class timeline li{display:none}
<ol id="update" class="timeline">
<?php
include('config.php');
//$post_id value comes from the POSTS table
$sql=mysql_query("select * from comments where post_id_fk='$post_id'");
while($row=mysql_fetch_array($sql))
{
$name=$row['com_name'];
$email=$row['com_email'];
$comment_dis=$row['com_dis'];
$lowercase = strtolower($email);
$image = md5( $lowercase );
?>
//Displaying existing or old comments
<li class="box">
<img src="http://www.gravatar.com/avatar.php?gravatar_id=<?php echo $image; ?>" class="com_img">
<span class="com_name"> <?php echo $name; ?></span> <br />
<?php echo $comment_dis; ?></li>
<?php
}
?>
</ol>
<div id="flash"></div>
<div >
<form action="#" method="post">
<input type="hidden" id="name" value="<?php echo $post_id; ?>"/>
<input type="text" id="name"/>Name<br />
<input type="text" id="email"/>Email<br />
<textarea id="comment"></textarea><br />
<input type="submit" class="submit" value=" Submit Comment " />
</form>
</div>


commentajax.php
Contains PHP and HTML code.
<?php
if($_POST)
{
$name=$_POST['name'];
$name=mysql_real_escape_string($name);
$email=$_POST['email'];
$email=mysql_real_escape_string($email);
$comment=$_POST['comment'];
$comment=mysql_real_escape_string($comment);
$post_id=$_POST['post_id'];
$post_id=mysql_real_escape_string($post_id);
$lowercase = strtolower($email);
$image = md5( $lowercase );
mysql_query("insert into comment(com_name,come_email,com_dis) values ('$name','$email','$comment_dis','$post_id')");
}

?>

<li class="box">
<img src="http://www.gravatar.com/avatar.php?gravatar_id=
<?php echo $image; ?>"/>
<?php echo $name;?><br />
<?php echo $comment; ?>
</li>

More jQuery and Ajax Tutorials : Take a look at this link


Download the testking 70-647 tutorials and testking 642-983 live demos to learn about jQuery connectivity with mysql, php and ajax. The testking 642-436 online training is the best way to improve your knowledge.
web notification

213 comments:

  1. Hmmm. You need to work on your query. They are not sanitized.

    ReplyDelete
  2. Sri, the script is great . I edited your old one and made it just like this .

    The only problem is > suppose there is a post that having 30 or more comments then you do not want to show all of them on a single page .. its a great thing if we add your "pagination" script with this script so it will become very handy but in this case we have to append latest comment on the top ? will it work ?

    ReplyDelete
  3. 30 or comments... I though that's just a simple example :) After all there is not filtration of data... SQL-injectino please welcome :)

    ReplyDelete
  4. since the li has display: none; the comments fetched from the database want show, you need to add style="display: list-item;" to the li in the first php script like you did in your demo ;)

    but really great script tho.

    ReplyDelete
  5. I have add some comments on the demo page but when i refresh the page there aren't my comments

    ReplyDelete
  6. Hi Kico,

    Demo not connected to database.

    ReplyDelete
  7. why it doesn't insert in mysql database what kind of this script. it shows inserted record temporary until you refresh the page. when you refresh page it remove all. please rectify this.

    ReplyDelete
  8. Great! i will use this in my website, Thanks ^^

    ReplyDelete
  9. how to put the added comment on top to be the first and not the last at the end.

    ReplyDelete
  10. Excuse me people but who the hell do you think you are commenting bad and rude replies and also demanding things. These people are sharing their work for free and have given their time. I suggest you all go and write it from scratch if you dont like you lazy son of a b***hes! And sql injection ...if your 'clever' enough to pick up on the fact that a script requires sanitising then you SHOULD be clever enough to actually sanitise the input data yourself. Blimey .... next you'll be asking for this guy to code your fricken websites!

    Be fair and respect the fact that you are getting something FOR FREE! Dont moan and be POLITE! Or like I said ... stop be so god damn lazy and write the code yourself!!!!!!!!!!!!!

    ReplyDelete
  11. thanks mr..^_^ this is that i've been looking for 4 months...^_^ thanks...thanks.. i'll try to applicate this code... ^_^

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. Hello this is a great script, i have based many scripts on this, but i discovered some bugs you might wanna check out:

    if you in the textarea write something like this:

    HEY
    LOOK
    AT
    ME

    (forecing next line by clicking return)

    the output will be:

    HEY LOOK AT ME (or something like this, in one line)

    my hack to fix this was to grap the $comment output from the database after i added it.

    another bug is the: & char, if you write:

    "me & you" the the output will break and display: "me " I don't know why that is neither do i have a solution right now but maybe you or someone else reading this could have a solution.

    ReplyDelete
  14. What about nested or threaded comments?

    ReplyDelete
  15. Hi Srinivas ,

    A nice script which I will use...

    One problem is that when you enter more than 6 lines of comment, the form overlays on top of the displayed comment.

    How does one control the positioning of the form to correct this problem?

    Thanks

    ReplyDelete
  16. very nice work bro

    ReplyDelete
  17. How can I conect to my database?

    Pedro

    ReplyDelete
  18. How to make all the comments fetched from the database visible despite refreshing site ? PLEASE HELP

    ReplyDelete
  19. hi,
    great script, but can you please help with the problem everybody has?

    How do we get comments to stay after a refresh!?

    ReplyDelete
  20. Great work! Hope to use it one day!

    ReplyDelete
  21. Hi, i found some bugs and would like to share the fix

    1. if you use '&' in a comment, it will break, what you need to do is to use params instead of a datastring like you do:

    var DataString = {
    'name': name,
    'email': email,
    'comment': comment,
    'post_id': post_id
    }

    then jQuery will automaticly encode it for you, and that will fix the '&' break problem.

    2. another bug is if you force new lines in the textarea the output will still be on one line.
    to fix this you must use the php function nl2br() on your $_POST['comment']; before you send it back as a response.

    ReplyDelete
  22. Is it secured? i want to add your great job to my official site? can u reply it? i afriad lose my server password to hacker

    ReplyDelete
  23. @daylight

    Yes I just modified commentajax.php

    ReplyDelete
  24. Hi,

    the script is connected with database but it doesn't save the comments in it. What should i do? (that's why i'm etting nothing after refresh)

    ReplyDelete
  25. Hi,

    I've solved my problem with refreshing. I've changed the line in commentajax.php. Now there is:

    mysql_query("insert into comments(com_name,com_email,com_dis,post_id_fk) values ('$name','$email','$comment_dis','$post_id')");

    ReplyDelete
  26. Hi,

    how can i add a new fields to the form so everything will work in mysql?

    ReplyDelete
  27. Hi I keep getting this error anyone has a tip? thanks


    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\Hosting\4811632\html\comment_system\comment.php on line 155

    ReplyDelete
  28. @EL Rey

    You need to check the sql statement

    ReplyDelete
  29. where? sorry but this is my first site and dont really know alot of php;

    ReplyDelete
  30. hi my comments are not showing up at all,also get the same message as above thanks for the scripts!

    ReplyDelete
  31. nice for sharing mate keep up the good work

    ReplyDelete
  32. hi, i hv done with the system, my problem is:

    do I need to create new table in database again for next page?

    becoz I dun wan old comments appear in the next page.

    Thanks for your help.

    ReplyDelete
  33. thanks for sharing such a good system, however, i still cant figure out how post_id_fk and post_id work? what do these two columns means?

    ReplyDelete
  34. awesome system! i'll be visiting your blog regularly~keep it up and appreciate your effort^^

    ReplyDelete
  35. For those who are noticing how the script doesn't save comments to the database, check out this line in commentajax.php:

    mysql_query("insert into comment(com_name,come_email,com_dis) values ('$name','$email','$comment_dis','$post_id')");

    First of all, change "come_email" to "com_email". That's a typo. Second and most importantly, change "$comment_dis" to "$comment".

    After I changed that, the comments were inserted into the database. However, everything disappears when the page is refreshed (the comments are still in the database.) I don't know how to fix that problem.

    ReplyDelete
  36. Ok, in comment.php look for this:

    $name=$row['com_name'];
    $email=$row['com_email'];
    $comment_dis=$row['com_dis'];

    Change "$comment_dis" to "$comment".

    Go down a little further until you see this line in between some span tags (the egg labs comment system won't let me post the span tags):

    class="com_name">

    There is a
    at the end of that line. Immediately after it press enter and on the next line write:



    ...before the closing li (list item) tag

    Voila - the posts will show on refresh and everytime you load the page.

    ReplyDelete
  37. the last part isn't showing up..
    what do we have to write?
    ;D

    ReplyDelete
  38. Please, fix the problem everybody has!
    and tell us how we connect it to the database properly, so the comments stay after a refresh.
    thanks in advance

    ReplyDelete
  39. Im having the same problem, can you help us?
    Thanks for the great script!

    ReplyDelete
  40. Here are connected with database, ok. But when refresh lost the comment, but if u look in Database the comment are there. I think must be somethink easy to repair. Seems like it can take the data in database to show again.

    Please help me ;)

    ReplyDelete
  41. Please, helpe us and put a link to donation!
    thanks

    ReplyDelete
  42. the comments are not displayed after refresh because the CSS sets display:none

    This will cure your problems. Soooo many typos and issues in that package. Not tested at all.... Shame as it is otherwise very useful.

    ReplyDelete
  43. Great Work!!! keep going!!!

    ReplyDelete
  44. how can i bring it together with your pagination?????


    sorry for my bad english^^

    ReplyDelete
  45. THERE IS A BIG PROBLEM WHEN YOU USED A WORD CONTAINING "&" character... using jquery.. for example.. NAME: ALBERT&TOM it will only get the word ALBERT and not the whole word.

    ReplyDelete
  46. Hi to all ,i no whats the problome ,the problome is whene we post the comment it save to database only the 2 row and it doesnt save the post_id if you see your databae the 2 row that you posted is there but the post_id id is(0)it shold save the post_id is well .thats why whene you refresh the page it doesnt show the comment . i have the same problome .
    hope all you guyes andrestand my lital chenglish write

    ReplyDelete
  47. hi there , i finly able to save all coment row to database .but whene i tray the next post on the same article id it get agin 0 post_id so it make me lital confuse cus i can`t post more then 1 post in article is any one there have the same problome i have

    ReplyDelete
  48. u can use append() or prepend() if you want :D

    ReplyDelete
  49. that is very cool, thank you so much for this.
    just i need to ask, what if i want to add reply to comments with some changes to the block of replies?

    ReplyDelete
  50. Very simple but very effective. I had it working in minutes, but for one bug I noticed: you have two inputs with the id of "name" which causes the form to be invalid and not be sent. Once that was fixed, it just worked.

    Great stuff.

    ReplyDelete
  51. Thanks for sharing the codes. Good job!

    ReplyDelete
  52. nice work thank you

    ReplyDelete
  53. What if i am using this on website and there is no post id

    ReplyDelete
  54. @Mikkel Oscar

    this worked for me, but the nl2br function does not worked for me :/

    ReplyDelete
  55. Just like Mikkel said,nl2br function...

    ReplyDelete
  56. Hi,

    This is what i am looking for.
    Now i want to extend this little bit more..
    I want "reply" facility against each comment...
    Can you help me

    ReplyDelete
  57. I had error :
    Notice: Undefined variable: post_id in C:\wamp\www\comment_updata\comment.php on line 158
    which is :
    $sql=mysql_query("select * from comments where post_id_fk='$post_id'");
    what do? for that , sorry I just start learn PHP and java ?
    can anyone help me plz ? thank you

    ReplyDelete
  58. This comment has been removed by the author.

    ReplyDelete
  59. $sql=mysql_query("select * from comments where post_id_fk='$post_id'");

    how can it get the $post_id value ?
    I see in commentajax.php there's a variabel $post_id, but the value is sent on submit.

    so how can that query work fine ?

    tks

    ReplyDelete
  60. I get this error Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /~/www/xtremetech.co.cc/Scripts/Comments/comment.php on line 135

    it seems to be on this line:
    while($row=mysql_fetch_array($sql))

    ReplyDelete
  61. for some reason the comments from data base not appear. :/

    ReplyDelete
  62. Hi Srinivas and all the good people over there!
    The script is great. I'm adapting it to use it with our Portal. The problem comes when I use special chars , like á é í ó ú or ñ
    It seems that the jquery stuff converts them into very strange chars and I cannot use them. I tested taking out all jquery stuff, and doing an old and common form post to commentajax.php and it works pretty fine. Perhaps I'm missing something? or there is an extra configuration that can be added to the jquery stuff? (I'm new to jquery).
    Another issue that I had and already solved was that, if i refreshed the page, the comments already stored in database were not shown. I just deleted display:none; from comment.php as various people said here.
    For those that have the problem of comments not being inserted in database at all, I recomend to echo de sql insert statement and run it in phpmyadmin to see the errors it has (it happened to me, I'm using completely different table name and field names, and was having trouble with a not null field I was forgetting to insert)
    Thanks Srinivas for this great work, and for sharing this with everyone.
    Sebastián

    ReplyDelete
  63. If I send 2 or more comments only the first go to data base. How can I solve that?

    ReplyDelete
  64. Hi Srinivas & People!
    It's me again.
    I could finally solve my problem, by decoding utf-8 back to iso in commentajax.php

    $comment = utf8_decode($_POST['comment']);

    Greetings!

    ReplyDelete
  65. Thank you! Everything works fine but for some reason the jquery isn't fading in and out. Anyone has any idea why?

    ReplyDelete
  66. Th, im gonna try it, but why dont you use this script on your site?

    ReplyDelete
  67. really loved the feature...planning to implement it

    ReplyDelete
  68. very simple and works great! good job my good sir! it would be nice to make a new one thought that updates automatically when other people post comments

    ReplyDelete
  69. This is a great tutorial, however a lot of typo error, i guess it would be better if you fix it before you post the download of the script.

    Other wise, its not working at all if there is a lot of error

    ReplyDelete
  70. Hey I love this script, but Im having a problem. Im using 000webhost and made a mysql database and everything. I plugged them into the config.php file but I get this message "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a2061535/public_html/comment.php on line 159" So I would love any help :D

    ReplyDelete
  71. just what it should be.... a good starting point for people that need a good starting point!

    Remember the old days? snippets and QED?? here you get working code... I think its great thanks for the effort.

    ReplyDelete
  72. Hey love the example!

    Was curious how to have a delete feature to the comment?

    ReplyDelete
  73. email validation is not working

    ReplyDelete
  74. how to design database???

    ReplyDelete
  75. Nice Script :), But email validation is not working !

    ReplyDelete
  76. Email validation is not working, and the comment itself is not stored in the database. the name and the email adress is.

    ReplyDelete
  77. Hello!

    I would like to know how can break long row with this comment system because I nowhere see that code.
    Could you help me?

    ReplyDelete
  78. hey i want to make it like this one....instead of email i want to display user's webpage/website

    ReplyDelete
  79. it don't works at my place. mysql database is always empty. also, I can't get $post_id. always is empty.

    ReplyDelete
  80. hemm.. its good, but where reply facility?

    ReplyDelete
  81. I wanna a delete function same like in fb .. I tried sumthing like "div id="delete Delete div
    input type="hidden value= it worked but I want as a script functionality . Can u suggest sumthing

    ReplyDelete
  82. Can u check for me..this error pop-ups when i tried to comment...please

    Notice: Undefined variable: post_id in C:\wampWaranz\www\comment_system\comment.php on line 156

    Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wampWaranz\www\comment_system\comment.php on line 157
    1. class="com_name"> awd


    Notice: Undefined variable: comment in C:\wampWaranz\www\comment_system\commentajax.php on line 23

    Loading Comment...
    Name*

    ReplyDelete
  83. Hello bro...currelty im doing my diploma project..i nid comment page..so i would to post urs into my system..can have the full script of this??? im using wamp server for my system. thanks alot bro...=)

    ReplyDelete
  84. I have tried everything i can to get previous comments to show up.. Anybody get it working that can provide the changes you made to the script? I would greatly apprectiate it.. Thanks in advance

    ReplyDelete
  85. JUST got it working with both the refresh working as well as the fades becasue before i was having the problem of either one or the other working.

    keep ol.timeline li{ display:none;
    in your css sheet but simple add the inline style in comment.php like this

    li class="box" style=" display:list-item;"

    that way everything will show up and get everything working.

    ReplyDelete
  86. should somewhere do insert comments to 'posts' first, if not, don't foreign 'comments' to 'posts' and erase all post_id.

    ReplyDelete
  87. for those who want to order comments by having the latest on TOP, add the "order by" to your query
    like so:
    mysql_query("SELECT * FROM comments ORDER BY comment_id DESC")

    ReplyDelete
  88. success: function(html){
    $("ol#update").append(html);
    $("ol#update li:last").fadeIn("slow");
    $("#flash").hide();
    }
    fadeIn didn't work for me, I had to .hide() it first before fadeIn(), otherwise it wouldn't work.

    ReplyDelete
  89. thanks for the script..............

    ReplyDelete
  90. for the users which still have problem with '&' and
    ( next line ) :
    for solving '&' problem, in JavaScript replace this :
    var dataString = 'name='+ name + '&email=' + email + '&comment=' + comment+ '&post_id=' + post_id;
    with this one :
    var DataString = {
    'name': name,
    'email': email,
    'comment': comment,
    'post_id': post_id
    }
    and for solving next line problem, in commentajax.php after this line :
    $comment=$_POST['comment'];
    add this :
    $comment = nl2br($comment_dis);
    $comment_insert = mysql_real_escape_string($comment_dis);
    and when you want to insert the comment to database, insert $comment_insert instead of $comment_dis.

    ReplyDelete
  91. in the above comment, for solving '&' problem, you must use dataString, not DataString ( d MUST be lower case, NOT CAPITAL, so use : )
    var dataString = {
    'name': name,
    'email': email,
    'comment': comment,
    'post_id': post_id
    }

    ReplyDelete
  92. how to put the added comment on top to be the first and not the last at the end.

    how to change it? plis give me a parameter to change it..

    ReplyDelete
  93. ahhhh..i find it..from coment first version
    set first to new comment

    $("ol#update").append(html);
    $("ol#update li:last").fadeIn("slow");
    -----------change it----------
    $("div#update").prepend(html); $("div#update div:first").fadeIn("slow");

    i'm use a div..not ol & li
    thx u so much bro :)

    ReplyDelete
  94. @andika
    nice work figuring that out.
    forgot about prepend :)

    ReplyDelete
  95. Hi. Sorry this might not be a question that i should ask..! bt how can i seperate old comments into pages.. let say show the number of comments on a side and also show only 8 comments in the current page and the rest are given page numbers with about 10 comments per page in date order?

    Thanks in Advance

    ReplyDelete
  96. I think i did something wrong, when i refresh all the comments are gone...
    Can someone help me?

    ReplyDelete
  97. Seba and Srinivas Tamada, you guys are genius, I got everything work by adding this:
    $comment = utf8_decode($_POST['comment']);

    ReplyDelete
  98. This comment is for those people who are asking page refresh question. I will discuss this problem in two sections :

    1. Problem : Problem is within commentajax.php insert query.

    2.Solution copy your query from phpmyadmin

    I hope it helps

    ReplyDelete
  99. Hello!
    Am trying to view the comment on the current reply id only!

    But its not working :( any suggestions?!

    Thanks!

    $("ol#update"+ReplyID).append(html);

    ReplyDelete
  100. Very good job, man! Whatever those guys, who claim that your code is somehow bad or incorrect, say, don't listen to them, cuz they see nobody else, but themselves. If someone's lookin' for code easy enough to understand it and build complex application based on it, it's not easy to find such code, because internet is full of arrogant asshol*s, who make it incredibly complicated only to point at their own geniousness! Thx again, mister!

    ReplyDelete
  101. Excuse me, but I still can't figure out where does variable $post_id comes from. It's used for selection in SELECT query, but I don't know, where does it come from?

    ReplyDelete
  102. Good script sir, but I am getting two errors
    1: Notice: Undefined variable: post_id in C:\wamp\www\comment_system\comment.php on line 158

    2:Notice: Undefined variable: comment in C:\wamp\www\comment_system\commentajax.php on line 23


    I have no idea how to resolve this, it is not getting the post id value plus on submission i get the second error...any help would be appreciated

    ReplyDelete
  103. Hi,
    I like this script, good job.
    But i do not understand what we will post and from where we will get data to post in posts table.
    We have FK in comment table but we cant get any data from post_id if we don't write something in.

    ReplyDelete
  104. Here "Posts" table contains articles post_id means article id.

    ReplyDelete
  105. BUG:::::::: If we hit the submit button twice,,,,comments are being inserted twice into database & repeated comments are displayed..in html.

    ReplyDelete
  106. How can I order the latest comment on top, but I mean the just uploaded comments in ajaxomment.php not the ones in comment.php

    ReplyDelete
  107. Latest comment on top replace following code

    $("ol#update").append(html);
    to
    $("ol#update").prepend(html);

    ReplyDelete
  108. Hello,
    How can i do so i show the previous posted comments?
    it just show a single one and that is the last one.

    ReplyDelete
  109. hello,

    i have a small question if i may:

    How to add 2 comment system in the same page, that will post comments in the same database but using 2 different POST ajax calls?

    thanks

    ReplyDelete
  110. very good work, just a few tweakings needed. Congratulations

    ReplyDelete
  111. hi thanks for ur job .. i made it but a message appear to me when i try it
    Notice: Undefined variable: post_id in C:\wamp\www\site\comment.php on line 184 Call Stack #TimeMemoryFunctionLocation 10.0018373568{main}( )..\comment.php:0 "/>
    can help me to fix it

    ReplyDelete
  112. Dont undestand a piece of shit

    ReplyDelete
  113. For lames like me it doesn't work and I'm really wondering why did you wrote this article. It's totally unusable for me and it's more over misleading. I'm going to find something else.

    ReplyDelete
  114. Tutorial Link Here
    9lessons | Programming blog
    Topics focus on programming, tutorials, jquery, ajax, php, mysql, javascript and java.


    Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in C:\xampp\htdocs\config.php on line 7
    Could not connect database

    ReplyDelete
  115. Hi there,
    trying to include this one into my page, but it seems like it's firing to another form which is present at my page. Checking for the comment field and saying it's not filled out. So as I'm really new to this ajax stuff, how can I get the script in checking forms[1] instead of the first one?
    If I'm trying it's not giving any error message but also not adding the comment to DB.

    Thanks in advance!

    ReplyDelete
  116. Hey I used your script however I noticed that sometimes the comments won't add. It will not display on the page or be added to the database. It is not a problem with the query because it adds other records. It's as if it works only sometimes.

    ReplyDelete
  117. Ive been trying to get this script to work. Ive inserted the SQL script and comments and posts are now in my database, but the comments.php script wont save the messages?? can someone help me plz

    ReplyDelete
  118. Is this page using your comment system?

    ReplyDelete
  119. Srinivas, thanks for sharing.
    I believe this page is using the Blogger/Google comments system.. . I'm wondering myself whether to use the comments with Blogger, or build my own (probably taking advantage of your tutorial)..
    With the one you built, would there be problems with spam I wonder...?

    ReplyDelete
  120. Finally got a break through
    Some changes in code
    comment.php
    li class="box" style="display:list-item;"

    span class="com_name">

    /span>



    commentajax.php

    mysql_query("INSERT INTO comments(com_name,com_email,com_dis,post_id_fk) VALUES('$name','$email','$comment_dis','$post_id')");

    li class="box" style="display:list-item;">

    ReplyDelete
  121. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /comments/comment.php on line 159

    What is it?

    ReplyDelete
  122. How can I add the comment to a concatenated list?

    ReplyDelete
  123. May i know where is Post_id table ?
    it is not sending any post_id , check the following ...

    < i n p u t t y pe = " h id d e n" n a m e = " p o st _ i d " i d = "p o st _ i d " va l u e= " " / >

    so How the Query will be executed ?
    as well as your Mysql Query is wrong

    ReplyDelete
  124. wow great script! thnx!

    ReplyDelete
  125. does this work here too?

    ReplyDelete
  126. I tried to move around but didn't works right, how can i move that forms to the top of list of comments message instead of showing forms after comment message!

    please advice

    AM

    ReplyDelete
  127. i moved the forms to the top of the comments list and when i test, is showing the comments but after refresh it does not showing, is clear that is not send data value to the database.

    what I'm trying to do is to show comments forms on top of the list of comments.

    any advice please!

    AM

    ReplyDelete
  128. What if we want next/previous feature for comments on this page? how can we do it?

    ReplyDelete
  129. How to use it without MySQL (database in file)?

    ReplyDelete
  130. Great script - thank you so much to share it with us! By the way the foreign key would work only when using innoDB as mysql engine. I'm generally using MYIsam so I've got to change the code. Not a problem for me but may be worth mentioning.

    ReplyDelete
  131. ... but it didn't work. You've got some realy big bugs inside that prevent the code from work.

    1)There is no element with ID="post". Instead there're two ID="name". I guess you overseen that simply. As consequence the post_id cant be submitted and without the value for the foreign key the query won't work.

    2) Anyways the query is buggy. It's like this:
    mysql_query("insert into comment(com_name,come_email,com_dis) values ('$name','$email','$comment_dis','$post_id')");

    But it sould look alike this:
    mysql_query("insert into comments(com_name, com_email, com_dis, post_id_fk) values ('$name','$email','$comment','$post_id')");

    Greetz
    Adrian

    ReplyDelete
  132. srinivas, can you reup the file; it's broken

    ramesh

    ReplyDelete
  133. hi wanna to display the two comment system in the single page i am getting the problem on the to submits plz help

    ReplyDelete
  134. for validation replace

    if(name=='' || email=='' || comment=='')
    {
    alert('Please Give Valid Details');
    }

    to

    var emailValido=/^.+@.+\..{2,}$/;
    if(name==''){
    alert('NAME MSG.');
    $('#name').focus();
    } else if(email==''){
    alert('EMAIL MSG.');
    $('#email').focus();
    } else if(!emailValido.test(email)){
    alert('INVALID EMAIL MSG');
    $('#email').focus();
    } else if(comment==''){
    alert('COMMENT MSG.');
    $('#comment').focus();
    }

    ReplyDelete
  135. Hi Srinivas Tamada,

    This tutorial looks awesome to me. But your share source script link is broken. Can you please share it again.

    Thanks

    ReplyDelete
  136. the comment not displaying on the page
    and not stored in database ...
    can any one help me for this .....

    ReplyDelete
  137. Posting using speech recognition

    ReplyDelete
  138. @Srinivas Tamada, Can you please post the tutorial to differentiate the comments of admin and users using the specified colors..as you have used..please.......i really need it.

    ReplyDelete
  139. Dan left a comment

    ReplyDelete
  140. I'm trying to come up with a way to have several different comment boxes on the same page. The blog will have numerous short articles and needs a separate comment section for each article. Is this possible with your system? If so, please provide some direction. Thank you.

    ReplyDelete
  141. Enter your comment...

    ReplyDelete
  142. Please, I need help. How can I use this script more than one time on the same page, on different articles, it works only on the first one?

    ReplyDelete
  143. Got to learn a lot from 9lessons ....! Looking at the demos that you have posted so far I think that I'm still an amateur and need to learn a lot from you. So thank you!

    ReplyDelete
  144. after i refresh the page comments disappear and data is not present in the database. i have tried to use all the suggestions but am still stuck

    ReplyDelete
  145. Hi, i really like this simple commenting system, but do you ever plan on adding website and reply features with it?

    ReplyDelete
  146. Interesting to see ... thank you it's well done :)

    ReplyDelete
  147. Hi, i really like simple commenting system on blogging thanks.

    ReplyDelete
  148. Thank you very much...

    ReplyDelete
  149. Hello, awesome work. I was wondering how do you add a REPLY button so that users can reply to specific comments instead of in the general area,

    ReplyDelete
  150. PHP code can be simply mixed with HTML code, or it can be used in combination with various templating engines and web frameworks. PHP code is usually processed by a PHP interpreter, which is usually implemented as a web server's native module or a Common Gateway Interface (CGI) executable.

    ReplyDelete
  151. Someone help me, connect script with mySQL ?

    ReplyDelete
  152. very useful information. Thanks!

    ReplyDelete

mailxengine Youtueb channel
Make in India
X