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.
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)
);
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');
}
$("#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>
<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">
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 );
<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
}
?>
<?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="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.
Hmmm. You need to work on your query. They are not sanitized.
ReplyDeleteSri, the script is great . I edited your old one and made it just like this .
ReplyDeleteThe 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 ?
30 or comments... I though that's just a simple example :) After all there is not filtration of data... SQL-injectino please welcome :)
ReplyDeletesince 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 ;)
ReplyDeletebut really great script tho.
I have add some comments on the demo page but when i refresh the page there aren't my comments
ReplyDeleteHi Kico,
ReplyDeleteDemo not connected to database.
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.
ReplyDeleteGreat! i will use this in my website, Thanks ^^
ReplyDeletehow to put the added comment on top to be the first and not the last at the end.
ReplyDeleteExcuse 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!
ReplyDeleteBe 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!!!!!!!!!!!!!
thanks mr..^_^ this is that i've been looking for 4 months...^_^ thanks...thanks.. i'll try to applicate this code... ^_^
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHello this is a great script, i have based many scripts on this, but i discovered some bugs you might wanna check out:
ReplyDeleteif 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.
What about nested or threaded comments?
ReplyDeleteHi Srinivas ,
ReplyDeleteA 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
very nice work bro
ReplyDeletetest the comment out
ReplyDeleteasfasfasfasf
ReplyDeleteHow can I conect to my database?
ReplyDeletePedro
faw
ReplyDeleteHow to make all the comments fetched from the database visible despite refreshing site ? PLEASE HELP
ReplyDeletehi,
ReplyDeletegreat script, but can you please help with the problem everybody has?
How do we get comments to stay after a refresh!?
Great work! Hope to use it one day!
ReplyDeleteHi, i found some bugs and would like to share the fix
ReplyDelete1. 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.
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@daylight
ReplyDeleteYes I just modified commentajax.php
Hi,
ReplyDeletethe 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)
Hi,
ReplyDeleteI'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')");
Hi,
ReplyDeletehow can i add a new fields to the form so everything will work in mysql?
Hi I keep getting this error anyone has a tip? thanks
ReplyDeleteWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\Hosting\4811632\html\comment_system\comment.php on line 155
@EL Rey
ReplyDeleteYou need to check the sql statement
where? sorry but this is my first site and dont really know alot of php;
ReplyDeletehi my comments are not showing up at all,also get the same message as above thanks for the scripts!
ReplyDeletenice for sharing mate keep up the good work
ReplyDeletehi, i hv done with the system, my problem is:
ReplyDeletedo 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.
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?
ReplyDeleteawesome system! i'll be visiting your blog regularly~keep it up and appreciate your effort^^
ReplyDeleteFor those who are noticing how the script doesn't save comments to the database, check out this line in commentajax.php:
ReplyDeletemysql_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.
Ok, in comment.php look for this:
ReplyDelete$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.
the last part isn't showing up..
ReplyDeletewhat do we have to write?
;D
Please, fix the problem everybody has!
ReplyDeleteand tell us how we connect it to the database properly, so the comments stay after a refresh.
thanks in advance
Im having the same problem, can you help us?
ReplyDeleteThanks for the great script!
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.
ReplyDeletePlease help me ;)
Please, helpe us and put a link to donation!
ReplyDeletethanks
the comments are not displayed after refresh because the CSS sets display:none
ReplyDeleteThis will cure your problems. Soooo many typos and issues in that package. Not tested at all.... Shame as it is otherwise very useful.
Great Work!!! keep going!!!
ReplyDeletehow can i bring it together with your pagination?????
ReplyDeletesorry for my bad english^^
Just a little test again.
ReplyDeleteTHERE 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.
ReplyDeleteHi 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 .
ReplyDeletehope all you guyes andrestand my lital chenglish write
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
ReplyDeleteu can use append() or prepend() if you want :D
ReplyDeletethat is very cool, thank you so much for this.
ReplyDeletejust i need to ask, what if i want to add reply to comments with some changes to the block of replies?
wow, nice
ReplyDeleteVery 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.
ReplyDeleteGreat stuff.
Thanks for sharing the codes. Good job!
ReplyDeletenice work thank you
ReplyDeleteWhat if i am using this on website and there is no post id
ReplyDeletethx
ReplyDelete@Mikkel Oscar
ReplyDeletethis worked for me, but the nl2br function does not worked for me :/
Just like Mikkel said,nl2br function...
ReplyDeleteHi,
ReplyDeleteThis 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
I had error :
ReplyDeleteNotice: 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
good amit script
ReplyDeleteThis comment has been removed by the author.
ReplyDelete$sql=mysql_query("select * from comments where post_id_fk='$post_id'");
ReplyDeletehow 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
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
ReplyDeleteit seems to be on this line:
while($row=mysql_fetch_array($sql))
@TOM
ReplyDeleteCheck the SQL statement.
for some reason the comments from data base not appear. :/
ReplyDeleteHi Srinivas and all the good people over there!
ReplyDeleteThe 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
If I send 2 or more comments only the first go to data base. How can I solve that?
ReplyDeleteHi Srinivas & People!
ReplyDeleteIt'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!
Thank you! Everything works fine but for some reason the jquery isn't fading in and out. Anyone has any idea why?
ReplyDeleteTh, im gonna try it, but why dont you use this script on your site?
ReplyDeletereally loved the feature...planning to implement it
ReplyDeletevery 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
ReplyDeleteThis 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.
ReplyDeleteOther wise, its not working at all if there is a lot of error
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
ReplyDeletejust what it should be.... a good starting point for people that need a good starting point!
ReplyDeleteRemember the old days? snippets and QED?? here you get working code... I think its great thanks for the effort.
Hey love the example!
ReplyDeleteWas curious how to have a delete feature to the comment?
email validation is not working
ReplyDeletehow to design database???
ReplyDeleteNice Script :), But email validation is not working !
ReplyDeletesalut
ReplyDeleteEmail validation is not working, and the comment itself is not stored in the database. the name and the email adress is.
ReplyDeleteHello!
ReplyDeleteI would like to know how can break long row with this comment system because I nowhere see that code.
Could you help me?
hey i want to make it like this one....instead of email i want to display user's webpage/website
ReplyDeleteit don't works at my place. mysql database is always empty. also, I can't get $post_id. always is empty.
ReplyDeletethanks dude
ReplyDeletehemm.. its good, but where reply facility?
ReplyDeleteI wanna a delete function same like in fb .. I tried sumthing like "div id="delete Delete div
ReplyDeleteinput type="hidden value= it worked but I want as a script functionality . Can u suggest sumthing
Can u check for me..this error pop-ups when i tried to comment...please
ReplyDeleteNotice: 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*
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...=)
ReplyDeleteI 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
ReplyDeleteJUST 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.
ReplyDeletekeep 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.
good work.
ReplyDeletewell well
ReplyDeleteReally nice (y)
ReplyDeleteshould somewhere do insert comments to 'posts' first, if not, don't foreign 'comments' to 'posts' and erase all post_id.
ReplyDeletefor those who want to order comments by having the latest on TOP, add the "order by" to your query
ReplyDeletelike so:
mysql_query("SELECT * FROM comments ORDER BY comment_id DESC")
success: function(html){
ReplyDelete$("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.
thanks for the script..............
ReplyDeleteNIce one :)
ReplyDeletefor the users which still have problem with '&' and
ReplyDelete( 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.
in the above comment, for solving '&' problem, you must use dataString, not DataString ( d MUST be lower case, NOT CAPITAL, so use : )
ReplyDeletevar dataString = {
'name': name,
'email': email,
'comment': comment,
'post_id': post_id
}
awesome
ReplyDeletegood
ReplyDeletehow to put the added comment on top to be the first and not the last at the end.
ReplyDeletehow to change it? plis give me a parameter to change it..
ahhhh..i find it..from coment first version
ReplyDeleteset 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 :)
@andika
ReplyDeletenice work figuring that out.
forgot about prepend :)
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?
ReplyDeleteThanks in Advance
nice
ReplyDeleteI think i did something wrong, when i refresh all the comments are gone...
ReplyDeleteCan someone help me?
thanx
ReplyDeleteSeba and Srinivas Tamada, you guys are genius, I got everything work by adding this:
ReplyDelete$comment = utf8_decode($_POST['comment']);
This comment is for those people who are asking page refresh question. I will discuss this problem in two sections :
ReplyDelete1. Problem : Problem is within commentajax.php insert query.
2.Solution copy your query from phpmyadmin
I hope it helps
Hello!
ReplyDeleteAm trying to view the comment on the current reply id only!
But its not working :( any suggestions?!
Thanks!
$("ol#update"+ReplyID).append(html);
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!
ReplyDeleteExcuse 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?
ReplyDeleteGood script sir, but I am getting two errors
ReplyDelete1: 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
Hi,
ReplyDeleteI 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.
Here "Posts" table contains articles post_id means article id.
ReplyDeleteNice script! Good job
ReplyDeleteBUG:::::::: If we hit the submit button twice,,,,comments are being inserted twice into database & repeated comments are displayed..in html.
ReplyDeleteHow can I order the latest comment on top, but I mean the just uploaded comments in ajaxomment.php not the ones in comment.php
ReplyDeleteLatest comment on top replace following code
ReplyDelete$("ol#update").append(html);
to
$("ol#update").prepend(html);
Hello,
ReplyDeleteHow can i do so i show the previous posted comments?
it just show a single one and that is the last one.
hello,
ReplyDeletei 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
very good work, just a few tweakings needed. Congratulations
ReplyDeletehi thanks for ur job .. i made it but a message appear to me when i try it
ReplyDeleteNotice: 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
hello .. thanks
ReplyDeleteDont undestand a piece of shit
ReplyDeletereally
ReplyDeleteFor 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.
ReplyDeletesounds easy to impleement
ReplyDeleteCool Post! ;)
ReplyDeleteNice, thank you
ReplyDeleteNice bad at all!
ReplyDeletegood
ReplyDeleteTutorial Link Here
ReplyDelete9lessons | 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
Hi there,
ReplyDeletetrying 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!
i like your web
ReplyDeletewow
ReplyDeleteComment cái coi
ReplyDeleteHey 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.
ReplyDeleteIve 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
ReplyDeleteIs this page using your comment system?
ReplyDeleteSrinivas, thanks for sharing.
ReplyDeleteI 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...?
Finally got a break through
ReplyDeleteSome 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;">
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /comments/comment.php on line 159
ReplyDeleteWhat is it?
How can I add the comment to a concatenated list?
ReplyDeleteits cool
ReplyDeleteMay i know where is Post_id table ?
ReplyDeleteit 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
Its nice
ReplyDeletegood
ReplyDeletewow great script! thnx!
ReplyDeletedoes this work here too?
ReplyDeletereally useful code
ReplyDeletetest comment
ReplyDeleteI 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!
ReplyDeleteplease advice
AM
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.
ReplyDeletewhat I'm trying to do is to show comments forms on top of the list of comments.
any advice please!
AM
What if we want next/previous feature for comments on this page? how can we do it?
ReplyDeleteHow to use it without MySQL (database in file)?
ReplyDeleteGreat 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... but it didn't work. You've got some realy big bugs inside that prevent the code from work.
ReplyDelete1)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
srinivas, can you reup the file; it's broken
ReplyDeleteramesh
great!!!
ReplyDeletehi wanna to display the two comment system in the single page i am getting the problem on the to submits plz help
ReplyDeletecool
ReplyDeletefor validation replace
ReplyDeleteif(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();
}
thanks a lot.
ReplyDeleteHi Srinivas Tamada,
ReplyDeleteThis tutorial looks awesome to me. But your share source script link is broken. Can you please share it again.
Thanks
the comment not displaying on the page
ReplyDeleteand not stored in database ...
can any one help me for this .....
:)
ReplyDeletePosting using speech recognition
ReplyDeleteDownload Script Updated.
ReplyDelete@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.
ReplyDeleteDan left a comment
ReplyDeleteI'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.
ReplyDeleteEnter your comment...
ReplyDeletePlease, 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?
ReplyDeleteNice Comment system , Thanks
ReplyDeleteGot 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!
ReplyDeleteafter 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
ReplyDeleteHi, i really like this simple commenting system, but do you ever plan on adding website and reply features with it?
ReplyDeleteInteresting to see ... thank you it's well done :)
ReplyDeleteHi, i really like simple commenting system on blogging thanks.
ReplyDeleteI love your script
ReplyDeleteThank you very much...
ReplyDeletenice to you
ReplyDeletenice
ReplyDeleteThank you to share
ReplyDeleteChanel shoes
super
ReplyDeleteHello, 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,
ReplyDeletePHP 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.
ReplyDeleteworking........thanks
ReplyDeleteSomeone help me, connect script with mySQL ?
ReplyDeletevery useful information. Thanks!
ReplyDeletecomment
ReplyDeleteGreat post
ReplyDelete