pushing dele and post for the board

This commit is contained in:
ismail 2017-02-09 16:47:06 +01:00
parent 5f6703e061
commit d7d569bfac
2 changed files with 80 additions and 0 deletions

18
deleteboard.php Normal file
View File

@ -0,0 +1,18 @@
<?php
//Include php-File mit DB Konfigurationen
require_once 'dbconfig.php';
//Verbindung zur DB herstellen
$mysql = new mysqli("localhost", $dbUsername, $dbPassword);
$mysql->select_db($dbName);
//ID auslesen, welche vom Link mittels GET mitgegeben wurde
$id = $_GET['id'];
//Eintrag dieser ID in der Tabelle löschen löschen
$mysql->query("DELETE FROM postboard WHERE id=" . $id);
//Seite board.php wieder anzeigen
header('Location: board.php');
?>

62
postboard.php Normal file
View File

@ -0,0 +1,62 @@
<?php
//Include php-File mit DB Konfigurationen
require_once 'dbconfig.php';
//Verbindung zur DB herstellen
$mysql = new mysqli("localhost", $dbUsername, $dbPassword);
$mysql->select_db($dbName);
$eintrag = "";
// Einlesen der Formular-Felder
if (isset($_POST['submit'])) {
$vorname = $_POST['vorname'];
$name = $_POST['name'];
$eintrag = $_POST['eintrag'];
//Eintrag in Tabelle erstellen mit den vom Benutzer eingegebenen Daten
$mysql->query("INSERT INTO demands(vorname, name, eintrag)
VALUES ('" . $vorname . "', '" . $name . "', '" . $eintrag . "')");
}
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Post</h1>
<h2>Neuer Eintrag</h2>
<form method="post" action="<?= $_SERVER['PHP_SELF'] ?>">Vorname<br />
<input type="text" name="vorname" value="" /><br />
Name<br />
<input type="text" name="name" value="" /><br />
<textarea rows="10" cols="60" name="eintrag"></textarea>
<br />
<input type="submit" name="submit" /></form>
<?php
// Abfrage aller Einträge der Tabelle
$eintraege = $mysql->query("SELECT id, vorname, name, eintrag,
date_format(datum,'%d.%m.%Y %H:%i') datumFormatiert FROM demands
ORDER BY datum");
// Ausgabe aller Einträge
while ($row = $eintraege->fetch_object()) {
echo "<h2>" . $row->vorname . " " . $row->name .
", " . $row->datumFormatiert . "</h2>";
echo $row->eintrag;
//Link erstellen zum Löschen des Eintrags
echo "<br/><a href='deleteboard.php?id=" . $row->id . "'>Löschen</a>";
echo "<br/><hr/>";
}
?>
</body>
</html>
<?php
//DB-Verbindung schliessen
$mysql->close();
?>