Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. <html>
  2. <head>
  3. <style type="text/css">
  4. table, th, td{
  5. border: 1px solid black;
  6. }
  7. </style>
  8.  
  9. <?php
  10.  
  11.  
  12. $servername = "localhost";
  13. $username = "root";
  14. $password = "123456";
  15. $dbname = "forum";
  16.  
  17. // Create connection
  18. $conn = new mysqli($servername, $username, $password, $dbname);
  19. // Check connection
  20. if ($conn->connect_error) {
  21. die("Connection failed: " . $conn->connect_error);
  22. }
  23.  
  24.  
  25. $sql = "SELECT * from posts ";
  26.  
  27. $result = $conn->query($sql);
  28.  
  29. echo "<center><h2>Recent Post</h2><table border='1'>
  30. <tr>
  31. <th>id</th>
  32. <th>username</th>
  33. <th>title</th>
  34. </tr></center>";
  35. while($row = $result->fetch_assoc())
  36. {
  37.  
  38. $id = $row['id'];
  39. echo "<tr>";
  40. echo "<td><a href='post2.php?id=$id'>$id</a></td>";
  41. echo "<td>" . htmlspecialchars($row['username']) ."
  42. </td>";
  43. echo "<td>" . htmlspecialchars($row['title']) . "</td>";
  44. echo "</tr>";
  45.  
  46. }
  47. echo "</table>";
  48.  
  49. $conn->close();
  50.  
  51. ?>
  52.  
  53.  
  54. <html>
  55. <body><br>
  56. <center>
  57. <form action="post2.php" method="post">
  58. <input name="submit" type="submit" value="Read More">
  59. </form>
  60. </center>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement