In This article we discussing about How to make a comment syetem using php, mysql and jquery. And comment will be inserted without page reload or refrashing. So for this we used AJAX (Asynchronous Java script And XML) . It is a big system so we are providing all the codes here.
For making This you need 3 pages with one folder as comment will be in images so Image folder is needed.
- db.php
- commentimage.php
- insert_comment.php
And in database there has a table named comment structure is below :
- id
- fk_image_id //For Inserting comment on a particular image
- fk_user_id //For Inserting which user is commenting
- comment
Step 1:
Make a db.php where database connection code is implemented.
<?php $con = mysqli_connect("localhost","root","","my_file_upload"); if(!$con){ echo "Failed"; } ?>
Step 2 :
Make a commentimage.php page and implement below codes.
Note: If you cannot understand this step you must see our previous article
<?php require_once('db.php'); $img_id = base64_decode($_GET['img_id']); $qry = mysqli_query($con,"SELECT * from `file_list` WHERE id='".$img_id."'"); $data = mysqli_fetch_assoc($qry); ?> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <!-- jQuery library --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!-- Latest compiled JavaScript --> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <link rel="stylesheet" type="text/css" href="comment.css"> <div class="container"> <div class="row"> <div class="col-md-8"> <h2 class="page-header">Uploaded By Sukalyan Kayal</h2> <section class="comment-list"> <!-- First Comment --> <!-- Second Comment Reply --> <article class="row"> <div class="col-md-12 col-sm-12"> <div class="panel panel-default"> <div class="panel-body"> <img src="my_file/<?php echo $data['file_name']; ?>" class="img-responsive"> </div> </div> </div> </article> <article class="row"> <div class="col-md-12 col-sm-12"> <div class="panel panel-default"> <div class="panel-body"> <div class="row"> <div class="col-md-8"> <input type="text" id="comment_value" class="form-control"> <input type="hidden" id="hidden_img_id" value="<?php echo $img_id; ?>"> </div> <div class="col-md-4"> <button id="comt_btn" class="btn btn-primary" onclick="comment_this()">Comment</button> </div> </div> </div> </div> </div> </article> <!-- Third Comment --> <div id="comment_div"> <?php $qqq = mysqli_query($con,"SELECT * from `comment` WHERE `fk_img_id` = '".$img_id."' order by id DESC"); while($row = mysqli_fetch_assoc($qqq)){ ?> <article class="row"> <div class="col-md-2 col-sm-2 hidden-xs"> <figure class="thumbnail"> <img class="img-responsive" src="http://www.keita-gaming.com/assets/profile/default-avatar-c5d8ec086224cb6fc4e395f4ba3018c2.jpg" /> <figcaption class="text-center">username</figcaption> </figure> </div> <div class="col-md-10 col-sm-10 col-xs-12"> <div class="panel panel-default arrow left"> <div class="panel-body"> <header class="text-left"> <div class="comment-user"><i class="fa fa-user"></i> That Guy</div> <time class="comment-date" datetime="16-12-2014 01:05"><i class="fa fa-clock-o"></i> Dec 16, 2014</time> </header> <div class="comment-post"> <p> <?php echo $row['comment']; ?> </p> </div> <p class="text-right"><a href="#" class="btn btn-default btn-sm"><i class="fa fa-reply"></i> reply</a></p> </div> </div> </div> </article> <?php } ?> </div> <!-- Fifth Comment --> </section> </div> </div> </div> <script> $(document).keypress(function(e){ var key = e.keyCode; if(key == 13) { $('#comt_btn').click(); } }); function comment_this(){ if($('#comment_value').val()==""){ $('#comment_value').focus(); $('#comment_value').attr("placeholder", "Type your comment first"); } else{ $.ajax({ type: 'post', url: 'insert_comment.php', data: {img_id:$('#hidden_img_id').val(), comment:$('#comment_value').val()}, success: function(result){ $('#comment_div').before(result); } }); } } </script>
Step 3:
Now make a insert_comment.php page for implement the comment inserting and implement the below codes.
<?php require_once('db.php'); $_POST['comment']; $_POST['img_id']; $qr = mysqli_query($con,"INSERT into `comment` (`fk_img_id`,`fk_user_id`,`comment`) values ('".$_POST['img_id']."','5','".$_POST['comment']."')"); if($qr){ $qry = mysqli_query($con,"SELECT * from `comment` order by `id` DESC LIMIT 1"); $data = mysqli_fetch_assoc($qry); } ?> <article class="row"> <div class="col-md-10 col-sm-10"> <div class="panel panel-default arrow right"> <div class="panel-body"> <header class="text-right"> <div class="comment-user"><i class="fa fa-user"></i> That Guy</div> <time class="comment-date" datetime="16-12-2014 01:05"><i class="fa fa-clock-o"></i> Dec 16, 2014</time> </header> <div class="comment-post"> <p> <?php echo $data['comment']; ?> </p> </div> <p class="text-right"><a href="#" class="btn btn-default btn-sm"><i class="fa fa-reply"></i> reply</a></p> </div> </div> </div> <div class="col-md-2 col-sm-2 hidden-xs"> <figure class="thumbnail"> <img class="img-responsive" src="http://www.keita-gaming.com/assets/profile/default-avatar-c5d8ec086224cb6fc4e395f4ba3018c2.jpg" /> <figcaption class="text-center">username</figcaption> </figure> </div> </article>
Related posts
good article
Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.
Sukalyan – should there be a ‘comment.css’ file with this?
referenced in ‘commentimage.php’ line 14.
Thank you for a great article.
Jim
Oh my goodness! an amazing article dude. Thank you However I am experiencing issue with ur rss . Don’t know why Unable to subscribe to it. Is there anybody getting equivalent rss downside? Anyone who knows kindly respond. Thnkx http://hellowh983mm.com
good lesson!
Thanks for the excellent guidance. This is the really great effort. Thank you.
http://www.slajobs.com/php-training-in-chennai.php
Nice blog and absolutely outstanding. You can do something much better but i still say this perfect.Keep trying for the best.
http://www.embeddedtraining.co.in
nice article.. thank you for sharing this.. Softlogic systems is one of the premier institutes for big data course in chennai training in Chennai. They have an excellent team of competent and dedicated trainers. http://www.softlogicsys.in/big-data-hadoop-training-in-chennai
Nice post. Thank you for sharing. keep going…
https://webdschool.com/digital-marketing-course-in-chennai.html
This is most informative and also this post most user friendly and super navigation to all posts… Thank you so much for giving this information to me..
rpa online training |
rpa course in bangalore |
rpa training in bangalore |
rpa training institute in bangalore
Wow, this piece of writing is good, my sister is analyzing these kinds
of things, therefore I am going to convey her.
Amazing post!!! This post is very comprehensive and i learn more ideas. Thanks for your post, i like more updates from your blog…
PHP Training in Bangalore
PHP Institutes in Bangalore
PHP Course in Chennai
PHP Course in Annanagar
PHP Course in Aminjikarai
PHP Course in Sholinganallur
Thanks for like our post.
Great Posting…
Keep doing it…
Thanks
Digital Marketing Certification Course in Chennai – Eminent Digital Academy
https://www.eminentdigitalacademy.com/
I really enjoyed while reading your article and it is good to know the latest updates. Do post more.
https://www.fita.in/rpa-training-chennai/
The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this.
Thanks for posting useful information.You have provided an nice article, Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things…Really it was an awesome article…very interesting to read..please sharing like this information……
Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
https://www.besanttechnologies.com/training-courses/amazon-web-services-training-in-bangalore
This is an awesome post.Really very informative and creative contents.These concept is a good way to enhance the knowledge.
I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
rpa training in bangalore
best blue prism online training
This is really an amazing article. Your article is really good and your article has always good thank you for information.
Hey there ! i come here for the fist time ! and i impressed with your writing and your blog
This post is very nice! It’s very interesting and I always like your post because your written style is very different. Keep it up…
blue prism training in chennai
I have read your excellent post. Thanks for sharing
aws training in chennai
big data training in chennai
iot training in chennai
data science training in chennai
blockchain training in chennai
rpa training in chennai
security testing training in chennai
Good blog!!! It is more impressive… thanks for sharing with us…
Selenium Training in Chennai
Big data training in chennai
Android Training in Chennai
Thanks for your valuable content, It is easy to understand and follow.
Amazing blog. Thanks for sharing with us.
python training in chennai
php training course
Thanks for sharing this informative blog
python training in chennai
php training
nice blog
get best placement at VSIPL
You shared useful post. Thanks for sharing.
Thanks for your valuable comment.
You have given a nice post to learn. learn more through blockchain course
Great Article, Thanks for sharing the Informative post. AWS Training in Tambaram
This is an awesome motivating article.I am practically satisfied with your great work.You put truly extremely supportive data. Keep it up. Continue blogging. Hoping to perusing your next post
Data Science Training
Great post i must say and thanks for the information.
Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.
Pretty! This has been an extremely wonderful post. Thanks for providing
this info.
Today, I went to the beachfront with my kids.
I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She put the shell
to her ear and screamed. There was a hermit crab inside and it pinched her ear.
She never wants to go back! LoL I know this is totally off topic but I had to tell someone!
Hmm it seems like your site ate my first comment (it was super long) so
I guess I’ll just sum it up what I submitted and say, I’m thoroughly enjoying your blog.
I too am an aspiring blog writer but I’m still new to everything.
Do you have any points for rookie blog writers? I’d certainly appreciate it.
I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.
I feel really happy to have seen your webpage and look forward to so many more Information reading here
Thank you for sharing valuable comments for us its very incredible post to whom looking for a particular course if any one who want to learn tally core to advance
Pretty! This was an extremely wonderful post. Many thanks for providing this info.
This article talks about interior design ideas for homes. It gives a brief outline on how bachelors may differ from married couples while decorating. It also sheds light on how a space can be utilized efficiently.