1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
<!DOCTYPE html>
<html lang="de-at">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<style>
* {margin:0;padding:0;}
p {margin:35px 0;}
html, body, div, h1, ul {border:0;outline:0;vertical-align:baseline;}
section {display:block;}
body {background:#fff;font:108% Arial, Helvetica, sans-serif;color:#000;text-align:left;font-weight:normal;}
#k-main {width:90%;max-width:1200px;margin:80px auto 45px auto;padding:0;line-height:1.2em;}
#k-main h1 {font-size:1.8em;font-weight:600;color:#600;text-align:center;padding:0;line-height:1.2em;}
.k-blatt {font-size:90%;color:#666;text-align:center;margin:25px 0;}
.k-cont {background:#f9f9f9;margin:25px 0;padding:5px 35px;border:#ccc 1px solid;}
.k-cont ul {list-style-type:none;margin:15px 0;line-height:1.2em;}
.k-continner {width:46%;float:left;padding:2%;}
.lab1 {width:95%;padding:10px;margin:10px 0;border:#ccc 1px solid;}
.lab2 {width:40px;text-align:center;padding:10px;margin:10px 0;border:#ccc 1px solid;}
.lab3 {background:#426300;color:#fff;font-size:90%;padding:15px 25px;margin-top:25px;border:none;}
.lab3:hover {background:#666;cursor:pointer;}
span.pflichtfeld {font-size:80%;color:#800;}
span.hilfetext {font-size:80%;color:#360;}
.k-ok {background:#360;color:#fff;padding:15px;}
.k-ko {background:#800;color:#fff;padding:15px;}
.clearfix:before,.clearfix:after {content: " ";display:table;}
.clearfix:after {clear:both;}
</style>
<body>
<section id="k-main">
<?php
if(!isset($_SESSION['user_id'])) {
die('<div class="k-blatt">Bitte zuerst <a title="Einloggen in den Admin- und Verwaltungsbereich" href="./">Einloggen</a></div>');
}
?>
<h1>Wenn Tabelle leer, dann Datensatz eintragen - ansonsten den Datensatz überschreiben.</h1>
<div class="k-blatt"><p>Bitte alle mit einem Stern markierten Felder ausfüllen.</p></div>
<?php
// Formular Eingaben
$p_nachname = isset($_POST["p_nachname"]) ? trim($_POST["p_nachname"]) : ""; // Nachname
$p_vorname = isset($_POST["p_vorname"]) ? trim($_POST["p_vorname"]) : ""; // Vorname
// Benutzereingaben überprüfen
$error = ["p_nachname"=>"", "p_vorname"=>"", "sicherheit"=>""];
if (isset($_POST["submit"])) {
$error["p_nachname"] = strlen($_POST["p_nachname"]) < 3 ? " Bitte füllen Sie dieses Feld aus (min. 3 Zeichen)!" : "";
$error["p_vorname"] = strlen($_POST["p_vorname"]) < 3 ? " Bitte füllen Sie dieses Feld aus (min. 3 Zeichen)!" : "";
$error["sicherheit"] = (md5($_POST["zip"]) != $_POST["zip2"]) ? "Die Rechenaufgabe ist leider falsch!" : "";
}
// Sicherheitsabfrage
$array = [1=>"eins", "zwei", "drei", "vier", "fünf", "sechs", "sieben", "acht", "neun", "zehn", "elf", "zwölf", "dreizehn", "vierzehn", "fünfzehn", "sechzehn", "siebzen", "achtzehn"];
$Z1 = mt_rand(1, 9);
$Z2 = mt_rand(1, 9);
$spam = " + " . $Z2 . " = " . $array[($Z1 + $Z2)];
$schutz = md5($Z1);
?>
<div class="k-cont clearfix">
<form action="test.php" autocomplete="off" method="post">
<div class="k-continner">
<br>
<ul>
<li><label>Nachname:
<span class='pflichtfeld'>* <?=$error['p_nachname']?></span><br>
<input type="text" name="p_nachname" value="<?=$p_nachname?>" class="lab1" required="required">
</label></li>
<li><label>Vorname:
<span class='pflichtfeld'>* <?=$error['p_vorname']?></span><br>
<input type="text" name="p_vorname" value="<?=$p_vorname?>" class="lab1" required="required">
</label></li>
</div>
<div class="k-continner">
<br>
<ul>
<li><label><span class="hilfetext">Sicherheitsabfrage: Bitte lösen Sie die Rechenaufgabe.</span>
<span class="pflichtfeld">* <?=$error["sicherheit"]?></span><br>
<input type="text" name="zip" class="lab2" required="required" autocomplete="off"><em><?=$spam?></em>
</label>
<input type="hidden" name="zip2" value="<?=$schutz?>"></li>
<li><input type="submit" name="submit" class="lab3" value="Daten eintragen"></li>
</ul>
</div>
</form>
</div>
<?php
// Verbindung Datenbank
require_once "incl/connect.php";
// Formular abgesendet
if (isset($_POST["submit"])) {
//Überprüfen Fehler
if (implode("", $error) == "") {
// Überprüfen ob Anzahl Datensatz bei 0
$stmt = $db->query("SELECT `id_test` FROM `wm_test`");
// Datensatz weniger als 1, dann Eintragen
if ($stmt->fetch() < 1) {
$insert = $db->prepare("INSERT INTO `wm_test`
SET
`p_nachname` = :p_nachname,
`p_vorname` = :p_vorname
");
$insert->bindValue(":p_nachname", $p_nachname);
$insert->bindValue(":p_vorname", $p_vorname);
}
else {
$insert = $db->prepare("UPDATE `wm_test`
SET
`p_nachname` = :p_nachname,
`p_vorname` = :p_vorname
");
$insert->bindValue(':p_nachname', $_POST["p_nachname"]);
$insert->bindValue(':p_vorname', $_POST["p_vorname"]);
}
//Führt die Einträge aus
if ($insert->execute()) {
echo "<p class='k-ok'>Die Daten wurden eingetragen.</p>";
}
else {
echo "<p class='k-ko'>Fehler beim Eintragen der Daten!";
}
}
}
// Ausgabe Datensatz
$select = $db->query("SELECT `p_nachname`, `p_vorname`
FROM `wm_test`");
$rows = $select->fetchAll(PDO::FETCH_OBJ);
foreach ($rows as $ausgabe) {
echo '<div class="k-cont">';
echo '<ul>';
echo '<li><b>Familienname:</b> ' . $ausgabe->p_nachname . '</li>';
echo '<li><b>Vorname:</b> ' . $ausgabe->p_vorname . '</li>';
echo '</ul>';
echo '</div>';
}
?>
</section>
</body>
</html>
|