Guest User

Untitled

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