Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html public "-//W3C//DTD HTML 4.0 //EN">
- <html>
- <head>
- <title>Title here!</title>
- <style type="text/css">
- <!--
- * {
- color:#000000;
- font-family:Arial;
- font-size:10pt;
- }
- body {
- background-color:#888888;
- }
- table {
- border-style:solid;
- border-width:1px;
- border-color:#000000;
- border-collapse:collapse;
- }
- td {
- padding:3px;
- }
- -->
- </style>
- </head>
- <body>
- <?php
- class MovieDatabase
- {
- public $db;
- public $dbhost = 'localhost';
- public $dbuser = 'root';
- public $dbpass = 'xxx';
- public $dbname = 'moviedb';
- public function __construct()
- {
- try
- {
- $db = new MySQLi($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname);
- echo "Verbindung aufgebaut!";
- }
- catch (Exception $e)
- {
- die("Verbindung zur DB fehlgeschlagen");
- }
- }
- public function newEntry()
- {
- // Film hinzufügen
- $sql = "insert into moviedb (titel, genre, fsk, laufzeit, jahr) values(?, ?, ?, ?, ?)";
- $command = $db->prepare($sql);
- $command->execute();
- $command->bind_param('sssss', $_POST['titel'], $_POST['genre'], $_POST['fsk'], $_POST['laufzeit'], $_POST['jahr']);
- }
- public function editEntry()
- {
- // Filmliste auslesen
- $sql = "select * from moviedb where id = $_POST[action]";
- $command = $db->prepare($sql);
- $command->execute();
- $command->bind_result($id, $titel, $genre, $fsk, $laufzeit, $jahr);
- // Genres auslesen
- # $sql2 = "select * from genres order by genre";
- # $command2 = $db->prepare($sql2);
- # $command2->execute();
- # $command2->bind_result('$genre_id, $genre_genre');
- }
- public function updateEntry()
- {
- // mysql_query("update moviedb set titel = '$_POST[titel]', genre = '$_POST[genre]', fsk = '$_POST[fsk]', laufzeit = '$_POST[laufzeit]', jahr = '$_POST[jahr]' where id = $_POST[update]");
- }
- public function deleteEntry()
- {
- // mysql_query("delete from moviedb where id=$_POST[action]");
- }
- }
- if(isset($_POST['neu']))
- {
- $mdb = new MovieDatabase();
- $mdb->newEntry();
- }
- elseif(isset($_POST['update']))
- {
- $mdb = new MovieDatabase();
- $mdb->updateEntry();
- }
- elseif(isset($_POST['delete']))
- {
- $mdb = new MovieDatabase();
- $mdb->editEntry();
- }
- else {
- $mdb = new MovieDatabase();
- }
- ?>
- <table>
- <!-- TABELLENKOPF -->
- <tr>
- <td>
- <b><a href="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>?sortierung=titel">Titel</a></b>
- </td>
- <td>
- <b><a href="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>?sortierung=genre">Genre</a></b>
- </td>
- <td>
- <b><a href="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>?sortierung=fsk">FSK</a></b>
- </td>
- <td>
- <b><a href="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>?sortierung=laufzeit">Laufzeit</a></b>
- </td>
- <td>
- <b><a href="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>?sortierung=jahr">Jahr</a></b>
- </td>
- <td>
- <b>Aktion</b>
- </td>
- </tr>
- <!-- EINTRAGEN / HINZUFÜGEN -->
- <tr>
- <td>
- <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">
- <?php
- if(isset($_POST['edit'])) {
- $mdb = new MovieDatabase();
- $mdb->editEntry();
- echo "<input type='hidden' name='update' value='$_POST[action]'>";
- }
- ?>
- <input type="text" name="titel" size="90" value="<?php if(isset($_POST['edit'])) { echo htmlspecialchars($titel); } ?>">
- </td>
- <td>
- <select name="genre">
- <option></option>
- <?php
- # while($command2->fetch()) {
- # if($genre == $genre_genre) {
- # $selected = "selected";
- # }
- # else {
- # $selected = "";
- # }
- # echo "<option name='".htmlspecialchars($genre_genre)."' $selected>".htmlspecialchars($genre_genre)."</option>";
- # }
- ?>
- </select>
- </td>
- <td>
- <input type="text" name="fsk" size="6" value="<?php if(isset($_POST['edit'])) { echo htmlspecialchars($fsk); }?>">
- </td>
- <td>
- <input type="text" name="laufzeit" size="6" value="<?php if(isset($_POST['edit'])) { echo htmlspecialchars($laufzeit); }?>">
- </td>
- <td>
- <input type="text" name="jahr" size="6" value="<?php if(isset($_POST['edit'])) { echo htmlspecialchars($jahr); }?>">
- </td>
- <td>
- <?php
- if(isset($_POST['edit'])) {
- echo "<input type='submit' value='Update'>";
- }
- else {
- echo "<input type='submit' name='neu' value='Eintragen'>";
- }
- ?>
- </form>
- </td>
- </tr>
- <!-- MOVIELISTE -->
- <?php
- if(isset($_GET['sortierung'])) {
- $sortierung=$_GET['sortierung'];
- }
- else {
- $sortierung="titel";
- }
- $sql = "select * from moviedb order by $sortierung";
- $command = $db->prepare($sql);
- $command->execute();
- $command->bind_result($id, $titel, $genre, $fsk, $laufzeit, $jahr);
- while($command->fetch()) {
- if($laufzeit != "") {
- $laufzeit .= " Min.";
- }
- ?>
- <form action='<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>' method='post' name='<?php echo "form".$id; ?>'>
- <input type='hidden' name='action' value='<?php echo $id; ?>'>
- <tr style='background-color:#888888;' onmouseover=\"style.backgroundColor='#999999'\" onmouseout=\"style.backgroundColor='#888888'\">
- <td><?php echo htmlspecialchars($titel); ?></td>
- <td><?php echo htmlspecialchars($genre); ?></td>
- <td><?php echo htmlspecialchars($fsk); ?></td>
- <td><?php echo htmlspecialchars($laufzeit); ?></td>
- <td><?php echo htmlspecialchars($jahr); ?></td>
- <td>
- <input type='submit' value='Bearbeiten' name='edit'>
- <input type='submit' value='Löschen' name='delete'>
- </td>
- </tr>
- </form>";
- <?php
- }
- ?>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement