Post and Comment Script

Language

Hi guys, In this code you will learn how to crate a Post and comment script which is very useful when you are developing a social networking site or any project that you want to put a Post and a comment system. Its design is from twitter bootstrap. Hope that you will like this code for more question email me at [email protected]. Thank you. Database name: post in db folder Sample code:
  1. <?php
  2. include('header.php');
  3. ?>
  4. <body>
  5. <br>
  6. <br>
  7. <div class="container">
  8. <form class="form-horizontal" method="POST">
  9. <div class="control-group">
  10. <div class="controls">
  11. <textarea rows="3" name="post_content" class="span6" placeholder="Whats on Your Mind"></textarea>
  12. </div>
  13. </div>
  14. <div class="control-group">
  15. <div class="controls">
  16. <button name="post" type="submit" class="btn btn-info"><i class="icon-share"></i>&nbsp;Post</button>
  17. </div>
  18. </div>
  19. <div class="control-group">
  20. <div class="controls">
  21. <table class="table table-bordered">
  22. <thead>
  23. </thead>
  24. <tbody>
  25. <?php
  26. $query=mysql_query("select * from post")or die(mysql_error());
  27. while($row=mysql_fetch_array($query)){
  28. $id=$row['post_id'];
  29. ?>
  30. <tr>
  31. <td><?php echo $row['content']; ?></td>
  32. <td width="50"><?php
  33. $comment_query=mysql_query("select * from comment where post_id='$id'")or die(mysql_error());
  34. $count=mysql_num_rows($comment_query);
  35. ?>
  36. <a href="#<?php echo $id; ?>" data-toggle="modal"><i class="icon-comments-alt"></i>&nbsp;<span class="badge badge-info"><?php echo $count; ?></span></a></td>
  37. <td width="40"><a class="btn btn-danger" href="delete_post.php<?php echo '?id='.$id; ?>"><i class="icon-trash"></i></a></td>
  38. </tr>
  39.  
  40. <!-- Modal -->
  41. <div id="<?php echo $id; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  42. <div class="modal-header"> </div>
  43. <div class="modal-body">
  44.  
  45. <!----comment -->
  46. <form method="POST">
  47. <input type="hidden" name="id" value="<?php echo $id; ?>">
  48. <textarea rows="3" name="comment_content" class="span6" placeholder="Your Comment Here"></textarea>
  49. <br>
  50. <br>
  51. <button name="comment" type="submit" class="btn btn-info"><i class="icon-share"></i>&nbsp;Comment</button>
  52. </form>
  53. <br>
  54. <br>
  55. <?php $comment=mysql_query("select * from comment where post_id='$id'")or die(mysql_error());
  56. while($comment_row=mysql_fetch_array($comment)){ ?>
  57. <div class="alert alert-success"><?php echo $comment_row['content']; ?></div>
  58. <?php } ?>
  59. <!--- end comment -->
  60.  
  61. </div>
  62. <div class="modal-footer">
  63. <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
  64. </div>
  65. </div>
  66. <?php } ?>
  67. </tbody>
  68. </table>
  69. </div>
  70. </div>
  71. </form>
  72. </div>
  73. <?php
  74. if(isset($_POST['post'])){
  75. $post_content=$_POST['post_content'];
  76.  
  77.  
  78. mysql_query("insert into post (content) values('$post_content')")or die(mysql_error());
  79. header('location:index.php');
  80.  
  81.  
  82. }
  83. ?>
  84. <?php
  85. if(isset($_POST['comment'])){
  86. $comment_content=$_POST['comment_content'];
  87. $post_id=$_POST['id'];
  88.  
  89. mysql_query("insert into comment (content,post_id) values('$comment_content',$post_id)")or die(mysql_error());
  90. header('location:index.php');
  91.  
  92.  
  93. }
  94. ?>
  95. </body>
  96. </html>

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Comments

Submitted byAnonymous (not verified)on Tue, 05/14/2013 - 17:39

Very good script.... jisu I wanna to ask you...why you have JS folder....when a delete that folder the script is working the same as before ::))) BTW good job
Submitted byAnonymous (not verified)on Fri, 05/31/2013 - 15:11

Thanks to give this code...... Thank you very muchhhh...
Submitted bymukhtion Thu, 11/24/2016 - 15:24

excellent code I have seen.
Submitted byStevie (not verified)on Tue, 01/17/2017 - 23:13

Just testing this for accuracy and workability. Great

Submitted byJoseph Nxakeni (not verified)on Tue, 07/04/2017 - 17:19

Hello i have upgraded the script i added features which display the username, comment, profile picture on the post email me for a zip file at [email protected]
Submitted byKevinohiro (not verified)on Sat, 09/30/2017 - 04:33

just testting to see if it will work
Submitted byahmed (not verified)on Fri, 01/19/2018 - 21:09

ahmed loves boys give him a new dad
Submitted byJordan Hackerson (not verified)on Thu, 01/25/2018 - 00:33

This is a great resource, and is definitely what I have been looking for! Thanks, and keep up the good work!
Submitted byjason1233131 (not verified)on Sun, 07/21/2019 - 05:24

Dont work wast of time
Submitted bylooks nice (not verified)on Sat, 09/10/2022 - 04:43

what if used in a single page what password is it looking for

Add new comment