Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $username = "root";
- $password = "";
- $database = "oop";
- $host = "localhost";
- mysql_connect($host, $username, $password);
- mysql_select_db($database);
- ?>
- <html>
- <head>
- </head>
- <body>
- <?php
- include("views/gaestebog.php");
- ?>
- </body>
- </html>
- <?php
- class Gaestebog {
- public function __contruct() {
- }
- public function getPosts() {
- $query = mysql_query("SELECT * FROM gaestebog");
- while ($row = mysql_fetch_array($query)) {
- echo '
- <tr>
- <td>'.$row['navn'].'</td>
- </tr>
- <tr>
- <td>'.$row['besked'].'</td>
- </tr>
- ';
- }
- }
- public function addPost($navn, $besked) {
- mysql_query("INSERT INTO gaestebog VALUES('', '$navn', '$besked')");
- }
- }
- ?>
- <?php
- include("classes/Gaestebog.php");
- $gaestebog = new Gaestebog();
- if (isset($_POST['opret'])) {
- $navn = $_POST['navn'];
- $besked = $_POST['besked'];
- $gaestebog->addPost($navn, $besked);
- }
- ?>
- <table>
- <?php
- $gaestebog->getPosts();
- ?>
- </table>
- <hr />
- <form action="" method="post">
- <table>
- <tr>
- <td>Navn:</td>
- <td><input type="text" name="navn" value="Patrick" /></td>
- </tr>
- <tr>
- <td>Besked:</td>
- <td><input type="text" name="besked" value="Hej med dig !!" /></td>
- </tr>
- <tr>
- <td><input type="submit" name="opret" value="Opret" /></td>
- </tr>
- </table>
- </form>
- mysql_connect($host, $username, $password);
- mysql_select_db($database);
- <?php
- require('bootstrap.php');
- $page = new Htmlpage('My Guestbook');
- $page->start($_SERVER['REQUEST_URI']);
- $gaestebog = new Gaestebog();
- echo '<table border="1">';
- foreach ($gaestebog->getPosts() as $post)
- {
- $row = new Htmlencoded($post);
- echo <<<OUT
- <tr>
- <td>$row['navn']</td>
- </tr>
- <tr>
- <td>$row['besked']</td>
- </tr>
- OUT;
- }
- echo '</table>';
- $page->closeRequest();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement