k3ll3r

Php

Sep 26th, 2016
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. <div id="content">
  2.  
  3. <?php
  4.  
  5. include"includes/connect.php";
  6.  
  7. $select_posts="select* from posts ";
  8. $run_posts=mysqli_query($con, $select_posts);
  9.  
  10. while($row=mysqli_fetch_array($run_posts)){
  11.  
  12. $post_id=$row['post_id'];
  13. $post_title=$row['post_title'];
  14. $post_date=$row['post_date'];
  15. $post_author=$row['post_author'];
  16. $post_image=$row['post_image'];
  17. $post_keywords=$row['post_keywords'];
  18. $post_content=$row['post_content'];
  19.  
  20.  
  21. ?>
  22. <h2> <?php echo $post_title; ?></h2>
  23.  
  24. <p align="left" > Published on: &nbsp;&nbsp; <b><?php echo $post_date; ?></b></p>
  25. <p align="right" > Posted by: &nbsp;&nbsp;<b><?php echo $post_author; ?></b></p>
  26. <center><img src="images/<?php echo $post_image; ?>" width="500" height="300"/></center>
  27. <p align="right"> <a href="">Read More</a></p>
  28. <?php
  29. echo "<form method = 'POST' action='content.php'>
  30. <input type='hidden' name='user_id' value='anonymous'>
  31. <input type='hidden' name='date' value='".date('Y-m-d H:i:s')."'>
  32. <textarea name='message'></textarea>
  33. <br>
  34. <button type ='submit' name ='commentSubmit'>comment</button>
  35. </form>";
  36. if(isset($_POST['commentSubmit'])){
  37. $uid=$_POST['user_id'];
  38. $date=$_POST['date'];
  39. $message=$_POST['message'];
  40.  
  41. $insert_comment="INSERT INTO comment(user_id, date,message) values('$uid','$date','$message')";
  42. $run_comment=mysqli_query($con,$insert_comment);
  43. // fetch data from the database
  44.  
  45.  
  46.  
  47.  
  48. }
  49. ?>
  50.  
  51. <?php
  52. $query = "SELECT * FROM comment, posts WHERE comment_id=$post_id";
  53.  
  54. if ($result= mysqli_query($con, $query)){
  55. while($row=mysqli_fetch_assoc($result)){
  56. echo "<div class='comment-box'>";
  57. echo $row ['user_id']."<br>";
  58. echo $row ['date']."<br><br>";
  59. echo nl2br ($row ['message']);
  60. echo"</div>";
  61. }
  62.  
  63. mysqli_free_result($result);
  64.  
  65. }
  66.  
  67.  
  68. ?>
  69.  
  70.  
  71. <p align="justify" > <b><?php echo $post_content; ?></b></p>
  72. <?php }?>
  73. </div>
Advertisement
Add Comment
Please, Sign In to add comment