Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##index.php
- <?php
- include 'inc.php';
- /* catch errors */
- if (mysqli_connect_errno()) {
- die('Konnte keine Verbindung zur Datenbank herstellen<br />MySQL meldete: <font color="red"><b>'.mysqli_connect_error().'</b></font>');
- }
- /* include the header template */
- include 'tmp/header.html';
- /* get news */
- $sql = 'SELECT
- Titel,
- Datum,
- Inhalt
- FROM
- News
- ORDER BY
- Datum DESC';
- $result = $db->query($sql);
- if (!$result) {
- die('Konnte den Query nicht senden: <b><font color="green">'.$sql.'</font></b><br />\nFehlermeldung: <b><font color="red">'.$db->error.'</font></b>');
- }
- if (!$result->num_rows) {
- echo '<p id="blue">Es sind keine Newsbeiträge vorhanden.</p>';
- } else {
- while ($row = $result->fetch_assoc()) {
- echo '<h1>'.$row['Titel']."</h1>\n";
- echo '<p id="date">'.$row['Datum']."</p>\n";
- echo '<p>'.$row['Inhalt']."</p>\n";
- }
- }
- /* include the footer template */
- include 'tmp/footer.html';
- ?>
- ##inc.php
- <?php
- function connect() {
- $host = "localhost"; // MySQL Host
- $user = "root"; // MySQL User
- $pass = ""; // MySQL Password
- $daba = "simple"; // MySQL Database
- $db = @new MySQLi($host, $user, $pass, $daba);
- return $db;
- }
- error_reporting(E_ALL);
- ini_set('display_errors', 1);
- /* connect to mysql database */
- $db = connect();
- ?>
- ##admin.php
- <?php
- include 'inc.php';
- if ($_POST) {
- $title = $_POST['Heading'];
- $text = $_POST['Text'];
- $passwort = "f27aba06ce4ebdbb24d614eea7a20b5c";
- if ($passwort == md5($_POST['Passwort'])) {
- if (empty($title) || empty($text)) {
- echo "<p id=\"yellow\">Bitte alle Felder ausfüllen!</p>";
- } else {
- $post = 'INSERT INTO news (`ID`, `Titel`, `Datum`, `Inhalt`) VALUES (NULL, "'.$title.'", NOW(), "'.$text.'")';
- $db->query($post);
- unset($title, $text);
- }
- } else {
- echo "<p id=\"red\">Das Passwort ist falsch!</p>";
- }
- }
- include 'tmp/header.html';
- ?>
- <form action="admin.php" method="post">
- <h1>Heading</h1><input type="text" name="Heading" size="70" value="<?php if (isset($title)) { echo $title; } ?>" />
- <textarea name="Text" cols="53" rows="5"><?php if (isset($text)) { echo $text; } ?></textarea><br />
- <h1>Password</h1><input type="password" name="Passwort" id="inpass" /> <input type="submit" name="sub" value="GO4MORE" />
- </form>
- <?php
- include 'tmp/footer.html';
- ?>
Add Comment
Please, Sign In to add comment