Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.70 KB | None | 0 0
  1. <!doctype html public "-//W3C//DTD HTML 4.0 //EN">
  2. <html>
  3. <head>
  4. <title>Title here!</title>
  5. <style type="text/css">
  6. <!--
  7. * {
  8. color:#000000;
  9. font-family:Arial;
  10. font-size:10pt;
  11. }
  12. body {
  13. background-color:#888888;
  14. }
  15. table {
  16. border-style:solid;
  17. border-width:1px;
  18. border-color:#000000;
  19. border-collapse:collapse;
  20. }
  21. td {
  22. padding:3px;
  23. }
  24. -->
  25. </style>
  26. </head>
  27. <body>
  28. <?php
  29.  
  30. class MovieDatabase
  31. {
  32. public $db;
  33. public $dbhost = 'localhost';
  34. public $dbuser = 'root';
  35. public $dbpass = 'xxx';
  36. public $dbname = 'moviedb';
  37.  
  38. public function __construct()
  39. {
  40. try
  41. {
  42. $db = new MySQLi($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname);
  43. echo "Verbindung aufgebaut!";
  44. }
  45. catch (Exception $e)
  46. {
  47. die("Verbindung zur DB fehlgeschlagen");
  48. }
  49. }
  50.  
  51. public function newEntry()
  52. {
  53. // Film hinzufügen
  54. $sql = "insert into moviedb (titel, genre, fsk, laufzeit, jahr) values(?, ?, ?, ?, ?)";
  55. $command = $db->prepare($sql);
  56. $command->execute();
  57. $command->bind_param('sssss', $_POST['titel'], $_POST['genre'], $_POST['fsk'], $_POST['laufzeit'], $_POST['jahr']);
  58.  
  59. }
  60. public function editEntry()
  61. {
  62. // Filmliste auslesen
  63. $sql = "select * from moviedb where id = $_POST[action]";
  64. $command = $db->prepare($sql);
  65. $command->execute();
  66. $command->bind_result($id, $titel, $genre, $fsk, $laufzeit, $jahr);
  67.  
  68. // Genres auslesen
  69. # $sql2 = "select * from genres order by genre";
  70. # $command2 = $db->prepare($sql2);
  71. # $command2->execute();
  72. # $command2->bind_result('$genre_id, $genre_genre');
  73.  
  74. }
  75. public function updateEntry()
  76. {
  77. // mysql_query("update moviedb set titel = '$_POST[titel]', genre = '$_POST[genre]', fsk = '$_POST[fsk]', laufzeit = '$_POST[laufzeit]', jahr = '$_POST[jahr]' where id = $_POST[update]");
  78. }
  79. public function deleteEntry()
  80. {
  81. // mysql_query("delete from moviedb where id=$_POST[action]");
  82. }
  83. }
  84.  
  85. if(isset($_POST['neu']))
  86. {
  87. $mdb = new MovieDatabase();
  88. $mdb->newEntry();
  89. }
  90. elseif(isset($_POST['update']))
  91. {
  92. $mdb = new MovieDatabase();
  93. $mdb->updateEntry();
  94. }
  95. elseif(isset($_POST['delete']))
  96. {
  97. $mdb = new MovieDatabase();
  98. $mdb->editEntry();
  99. }
  100. else {
  101. $mdb = new MovieDatabase();
  102. }
  103.  
  104. ?>
  105. <table>
  106.  
  107. <!-- TABELLENKOPF -->
  108.  
  109. <tr>
  110. <td>
  111. <b><a href="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>?sortierung=titel">Titel</a></b>
  112. </td>
  113. <td>
  114. <b><a href="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>?sortierung=genre">Genre</a></b>
  115. </td>
  116. <td>
  117. <b><a href="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>?sortierung=fsk">FSK</a></b>
  118. </td>
  119. <td>
  120. <b><a href="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>?sortierung=laufzeit">Laufzeit</a></b>
  121. </td>
  122. <td>
  123. <b><a href="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>?sortierung=jahr">Jahr</a></b>
  124. </td>
  125. <td>
  126. <b>Aktion</b>
  127. </td>
  128. </tr>
  129.  
  130. <!-- EINTRAGEN / HINZUFÜGEN -->
  131.  
  132. <tr>
  133. <td>
  134. <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">
  135. <?php
  136. if(isset($_POST['edit'])) {
  137. $mdb = new MovieDatabase();
  138. $mdb->editEntry();
  139. echo "<input type='hidden' name='update' value='$_POST[action]'>";
  140. }
  141. ?>
  142. <input type="text" name="titel" size="90" value="<?php if(isset($_POST['edit'])) { echo htmlspecialchars($titel); } ?>">
  143. </td>
  144. <td>
  145. <select name="genre">
  146. <option></option>
  147. <?php
  148. # while($command2->fetch()) {
  149. # if($genre == $genre_genre) {
  150. # $selected = "selected";
  151. # }
  152. # else {
  153. # $selected = "";
  154. # }
  155. # echo "<option name='".htmlspecialchars($genre_genre)."' $selected>".htmlspecialchars($genre_genre)."</option>";
  156. # }
  157. ?>
  158. </select>
  159. </td>
  160. <td>
  161. <input type="text" name="fsk" size="6" value="<?php if(isset($_POST['edit'])) { echo htmlspecialchars($fsk); }?>">
  162. </td>
  163. <td>
  164. <input type="text" name="laufzeit" size="6" value="<?php if(isset($_POST['edit'])) { echo htmlspecialchars($laufzeit); }?>">
  165. </td>
  166. <td>
  167. <input type="text" name="jahr" size="6" value="<?php if(isset($_POST['edit'])) { echo htmlspecialchars($jahr); }?>">
  168. </td>
  169. <td>
  170. <?php
  171. if(isset($_POST['edit'])) {
  172. echo "<input type='submit' value='Update'>";
  173. }
  174. else {
  175. echo "<input type='submit' name='neu' value='Eintragen'>";
  176. }
  177. ?>
  178. </form>
  179. </td>
  180. </tr>
  181.  
  182. <!-- MOVIELISTE -->
  183.  
  184. <?php
  185. if(isset($_GET['sortierung'])) {
  186. $sortierung=$_GET['sortierung'];
  187. }
  188. else {
  189. $sortierung="titel";
  190. }
  191. $sql = "select * from moviedb order by $sortierung";
  192. $command = $db->prepare($sql);
  193. $command->execute();
  194. $command->bind_result($id, $titel, $genre, $fsk, $laufzeit, $jahr);
  195. while($command->fetch()) {
  196. if($laufzeit != "") {
  197. $laufzeit .= " Min.";
  198. }
  199. ?>
  200. <form action='<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>' method='post' name='<?php echo "form".$id; ?>'>
  201. <input type='hidden' name='action' value='<?php echo $id; ?>'>
  202. <tr style='background-color:#888888;' onmouseover=\"style.backgroundColor='#999999'\" onmouseout=\"style.backgroundColor='#888888'\">
  203. <td><?php echo htmlspecialchars($titel); ?></td>
  204. <td><?php echo htmlspecialchars($genre); ?></td>
  205. <td><?php echo htmlspecialchars($fsk); ?></td>
  206. <td><?php echo htmlspecialchars($laufzeit); ?></td>
  207. <td><?php echo htmlspecialchars($jahr); ?></td>
  208. <td>
  209. <input type='submit' value='Bearbeiten' name='edit'>
  210. <input type='submit' value='Löschen' name='delete'>
  211. </td>
  212. </tr>
  213. </form>";
  214. <?php
  215. }
  216. ?>
  217. </table>
  218. </body>
  219. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement