Advertisement
Guest User

Untitled

a guest
Jul 4th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. <?php
  2. $username = "root";
  3. $password = "";
  4. $database = "oop";
  5. $host = "localhost";
  6.  
  7. mysql_connect($host, $username, $password);
  8. mysql_select_db($database);
  9. ?>
  10. <html>
  11. <head>
  12. </head>
  13. <body>
  14. <?php
  15. include("views/gaestebog.php");
  16. ?>
  17. </body>
  18. </html>
  19.  
  20. <?php
  21. class Gaestebog {
  22.  
  23. public function __contruct() {
  24.  
  25. }
  26.  
  27. public function getPosts() {
  28. $query = mysql_query("SELECT * FROM gaestebog");
  29. while ($row = mysql_fetch_array($query)) {
  30. echo '
  31. <tr>
  32. <td>'.$row['navn'].'</td>
  33. </tr>
  34. <tr>
  35. <td>'.$row['besked'].'</td>
  36. </tr>
  37. ';
  38. }
  39. }
  40.  
  41. public function addPost($navn, $besked) {
  42. mysql_query("INSERT INTO gaestebog VALUES('', '$navn', '$besked')");
  43. }
  44. }
  45. ?>
  46.  
  47. <?php
  48. include("classes/Gaestebog.php");
  49. $gaestebog = new Gaestebog();
  50. if (isset($_POST['opret'])) {
  51. $navn = $_POST['navn'];
  52. $besked = $_POST['besked'];
  53. $gaestebog->addPost($navn, $besked);
  54. }
  55. ?>
  56. <table>
  57. <?php
  58. $gaestebog->getPosts();
  59. ?>
  60. </table>
  61.  
  62. <hr />
  63.  
  64. <form action="" method="post">
  65. <table>
  66. <tr>
  67. <td>Navn:</td>
  68. <td><input type="text" name="navn" value="Patrick" /></td>
  69. </tr>
  70. <tr>
  71. <td>Besked:</td>
  72. <td><input type="text" name="besked" value="Hej med dig !!" /></td>
  73. </tr>
  74. <tr>
  75. <td><input type="submit" name="opret" value="Opret" /></td>
  76. </tr>
  77. </table>
  78. </form>
  79.  
  80. mysql_connect($host, $username, $password);
  81. mysql_select_db($database);
  82.  
  83. <?php
  84. require('bootstrap.php');
  85.  
  86. $page = new Htmlpage('My Guestbook');
  87. $page->start($_SERVER['REQUEST_URI']);
  88.  
  89. $gaestebog = new Gaestebog();
  90.  
  91. echo '<table border="1">';
  92.  
  93. foreach ($gaestebog->getPosts() as $post)
  94. {
  95. $row = new Htmlencoded($post);
  96.  
  97. echo <<<OUT
  98. <tr>
  99. <td>$row['navn']</td>
  100. </tr>
  101. <tr>
  102. <td>$row['besked']</td>
  103. </tr>
  104. OUT;
  105. }
  106. echo '</table>';
  107.  
  108. $page->closeRequest();
  109. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement