Voll Upload SGD Fachinformatiker PHP
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
class Bestell {
|
||||
private $tabelle = "artikel";
|
||||
|
||||
private function baueBestellTabelle($sql) {
|
||||
require_once("db.inc.php");
|
||||
|
||||
if ($stmt = $pdo -> prepare($sql)) {
|
||||
$stmt -> execute();
|
||||
|
||||
echo "<table>\n\t";
|
||||
echo "<thead>
|
||||
|
||||
<tr>
|
||||
<th>Artikelnummer</th><th>Artikelgruppe</th><th>Artikelbezeichnung</th><th>Preis</th>
|
||||
</tr>
|
||||
</thead>";
|
||||
|
||||
echo "<tbody>\n\t";
|
||||
|
||||
while ($z = $stmt -> fetch()) {
|
||||
|
||||
echo "<tr "
|
||||
|
||||
.">\n\t<td>"
|
||||
|
||||
. htmlspecialchars($z['anr'])
|
||||
|
||||
."</td>\n\t<td>"
|
||||
|
||||
. htmlspecialchars($z['gnr'])
|
||||
|
||||
."</td>\n\t<td>"
|
||||
|
||||
. htmlspecialchars($z['name'])
|
||||
|
||||
."</td>\n\t<td>"
|
||||
|
||||
. htmlspecialchars($z['preis'])
|
||||
|
||||
."</td>\n\t";
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
public function lesenAlleDaten() {
|
||||
$sql = "SELECT anr, gnr, name, preis
|
||||
FROM " .$this->tabelle ."
|
||||
ORDER BY anr";
|
||||
|
||||
$this->baueBestellTabelle($sql);
|
||||
}
|
||||
|
||||
public function lesenGruppe() {
|
||||
$sql = "SELECT artikel.anr, gruppen.gruppe AS gnr, artikel.name, artikel.preis FROM " .$this->tabelle ."
|
||||
JOIN gruppen ON artikel.gnr = gruppen.gnr
|
||||
ORDER BY artikel.anr";
|
||||
|
||||
$this->baueBestellTabelle($sql);
|
||||
}
|
||||
|
||||
public function loeschen($id){
|
||||
require("db.inc.php");
|
||||
|
||||
$sql = "DELETE FROM " .$this->tabelle ." WHERE anr = :anr";
|
||||
|
||||
if($stmt = $pdo->prepare($sql)) {
|
||||
$stmt->bindParam(':anr', $id);
|
||||
$stmt->execute();
|
||||
echo "Artikel gelöscht";
|
||||
}
|
||||
else {
|
||||
echo "Fehler beim Löschen";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function einfuegenSelect($tab, $val, $text, $def) {
|
||||
$s = "<select name =\"" .$val . "\" id= \"" . $val . "\">";
|
||||
|
||||
require("db.inc.php");
|
||||
|
||||
$sql = "SELECT " .$val . ", " . $text . " FROM " .$tab;
|
||||
|
||||
//$sql = "SELECT anr, gnr, name FROM artikel";
|
||||
|
||||
if ($stmt = $pdo->prepare($sql)) {
|
||||
$stmt->execute();
|
||||
|
||||
while ($z = $stmt->fetch()) {
|
||||
$s = $s . "<option value=\"" . $z[0] . "\"";
|
||||
|
||||
if($z[0] == $def) {
|
||||
$s = $s . " selected";
|
||||
}
|
||||
|
||||
$s = $s . ">" . $z[0] ." | " . $z[1] ."</option>";
|
||||
}
|
||||
$s = $s . "</select>";
|
||||
|
||||
return $s;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
$dbuser = 'root';
|
||||
$dbpw = 'Feuerwehr1!';
|
||||
$dbhost = 'localhost';
|
||||
$dbname = 'bestelldatenbank';
|
||||
|
||||
try {
|
||||
$pdo = new PDO ("mysql:dbname=$dbname;host=$dbhost;charset=utf8", $dbuser, $dbpw);
|
||||
} catch (PDOException $e) {
|
||||
die ($e->getMessage());
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
||||
<title>e1_artikel_ausgeben</title>
|
||||
|
||||
<?php
|
||||
require_once("bestellen.class.php")
|
||||
?>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h1>Artikel ausgeben</h1>
|
||||
|
||||
|
||||
<div class="ausgabe">
|
||||
<?php
|
||||
|
||||
$teilnehmer = new Bestell();
|
||||
|
||||
$teilnehmer->lesenAlleDaten();
|
||||
|
||||
?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
||||
<title>e2_gruppenbezeichnung</title>
|
||||
|
||||
<?php
|
||||
require_once("bestellen.class.php")
|
||||
?>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h1>Artikel ausgeben</h1>
|
||||
|
||||
|
||||
<div class="ausgabe">
|
||||
<?php
|
||||
|
||||
$bestell = new Bestell();
|
||||
|
||||
$bestell->lesenGruppe();
|
||||
?>
|
||||
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,40 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
||||
<title>e3_artikel_löschen</title>
|
||||
|
||||
<?php
|
||||
require_once("bestellen.class.php")
|
||||
?>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h1>Artikel Löschen</h1>
|
||||
|
||||
|
||||
<div class="ausgabe">
|
||||
<?php
|
||||
|
||||
$bestell = new Bestell();
|
||||
|
||||
// Prüfen ob Formular abgeschickt wurde
|
||||
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['anr'])) {
|
||||
$anr = $_POST['anr'];
|
||||
$bestell->loeschen($anr);
|
||||
}
|
||||
|
||||
?>
|
||||
<!-- Formularfelder erstellen -->
|
||||
<form method="post">
|
||||
<label for="anr">Artikel: </label>
|
||||
<?php echo $bestell->einfuegenSelect("artikel", "anr" ,"name", "anr"); ?>
|
||||
<input type="submit" value="auswahl">
|
||||
|
||||
</form>
|
||||
<?php
|
||||
|
||||
?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user