Guest User

Untitled

a guest
Jul 12th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. ##index.php
  2. <?php
  3.  
  4. include 'inc.php';
  5.  
  6. /* catch errors */
  7. if (mysqli_connect_errno()) {
  8. die('Konnte keine Verbindung zur Datenbank herstellen<br />MySQL meldete: <font color="red"><b>'.mysqli_connect_error().'</b></font>');
  9. }
  10.  
  11. /* include the header template */
  12. include 'tmp/header.html';
  13.  
  14. /* get news */
  15. $sql = 'SELECT
  16. Titel,
  17. Datum,
  18. Inhalt
  19. FROM
  20. News
  21. ORDER BY
  22. Datum DESC';
  23.  
  24. $result = $db->query($sql);
  25.  
  26. if (!$result) {
  27. die('Konnte den Query nicht senden: <b><font color="green">'.$sql.'</font></b><br />\nFehlermeldung: <b><font color="red">'.$db->error.'</font></b>');
  28. }
  29.  
  30. if (!$result->num_rows) {
  31. echo '<p id="blue">Es sind keine Newsbeiträge vorhanden.</p>';
  32. } else {
  33. while ($row = $result->fetch_assoc()) {
  34. echo '<h1>'.$row['Titel']."</h1>\n";
  35. echo '<p id="date">'.$row['Datum']."</p>\n";
  36. echo '<p>'.$row['Inhalt']."</p>\n";
  37. }
  38. }
  39.  
  40. /* include the footer template */
  41. include 'tmp/footer.html';
  42. ?>
  43. ##inc.php
  44. <?php
  45. function connect() {
  46. $host = "localhost"; // MySQL Host
  47. $user = "root"; // MySQL User
  48. $pass = ""; // MySQL Password
  49. $daba = "simple"; // MySQL Database
  50.  
  51. $db = @new MySQLi($host, $user, $pass, $daba);
  52.  
  53. return $db;
  54. }
  55.  
  56. error_reporting(E_ALL);
  57. ini_set('display_errors', 1);
  58.  
  59. /* connect to mysql database */
  60. $db = connect();
  61.  
  62. ?>
  63. ##admin.php
  64. <?php
  65.  
  66. include 'inc.php';
  67.  
  68. if ($_POST) {
  69. $title = $_POST['Heading'];
  70. $text = $_POST['Text'];
  71. $passwort = "f27aba06ce4ebdbb24d614eea7a20b5c";
  72.  
  73. if ($passwort == md5($_POST['Passwort'])) {
  74. if (empty($title) || empty($text)) {
  75. echo "<p id=\"yellow\">Bitte alle Felder ausfüllen!</p>";
  76. } else {
  77. $post = 'INSERT INTO news (`ID`, `Titel`, `Datum`, `Inhalt`) VALUES (NULL, "'.$title.'", NOW(), "'.$text.'")';
  78. $db->query($post);
  79. unset($title, $text);
  80. }
  81. } else {
  82. echo "<p id=\"red\">Das Passwort ist falsch!</p>";
  83. }
  84. }
  85.  
  86. include 'tmp/header.html';
  87. ?>
  88.  
  89. <form action="admin.php" method="post">
  90. <h1>Heading</h1><input type="text" name="Heading" size="70" value="<?php if (isset($title)) { echo $title; } ?>" />
  91. <textarea name="Text" cols="53" rows="5"><?php if (isset($text)) { echo $text; } ?></textarea><br />
  92. <h1>Password</h1><input type="password" name="Passwort" id="inpass" /> <input type="submit" name="sub" value="GO4MORE" />
  93. </form>
  94.  
  95. <?php
  96. include 'tmp/footer.html';
  97. ?>
Add Comment
Please, Sign In to add comment