2018-05-26 16:55:33 +02:00
|
|
|
<?php
|
2018-05-26 15:59:43 +02:00
|
|
|
|
2018-05-26 16:55:33 +02:00
|
|
|
if(isset($_POST['tan'])){
|
2018-05-27 19:31:44 +02:00
|
|
|
//echo "Tan ->" . $_POST['tan'] . "<-";
|
|
|
|
if($_POST['tan'] != ""){
|
|
|
|
addEntry();
|
|
|
|
consumeTan($_POST['tan']);
|
|
|
|
}
|
2018-05-26 16:55:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function addEntry() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function consumeTan($tan) {
|
|
|
|
//Stelle DB verbindung her
|
|
|
|
$user = 'root';
|
|
|
|
$password = 'root';
|
|
|
|
$db = 'friendsbook';
|
|
|
|
$host = 'localhost';
|
|
|
|
$port = 3306;
|
|
|
|
|
|
|
|
$database = new mysqli($host, $user, $password, $db, $port);
|
|
|
|
|
|
|
|
if ($database->connect_error) {
|
|
|
|
die('Connect Error (' . $database->connect_errno . ') ' . $database->connect_error);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Stelle sicher dass die Tan noch verfügbar ist.
|
|
|
|
$abfrage = "SELECT `used`, `tan` FROM `tans` WHERE `tan` = '" . $tan . "'";
|
|
|
|
$ergebnis = mysqli_query($database, $abfrage);
|
|
|
|
|
2018-05-27 19:31:44 +02:00
|
|
|
if($ergebnis->num_rows == 0){
|
|
|
|
echo "Tan nicht vergeben";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-26 16:55:33 +02:00
|
|
|
$resultStr = "";
|
|
|
|
|
|
|
|
while ($row = $ergebnis->fetch_assoc()) {
|
|
|
|
$resultStr = $resultStr . $row["used"] . ' ' . $row["tan"] . '<br>';
|
|
|
|
if($row["used"] == 1){
|
|
|
|
echo "Tan schon verbraucht";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//echo $resultStr;
|
|
|
|
|
|
|
|
//Setzte Tan auf verbraucht
|
|
|
|
$update = $database->query("UPDATE `tans` SET `used`= true WHERE `tan` = '" . $_POST['tan'] . "'");
|
|
|
|
|
|
|
|
echo "Tan verbraucht " . $_POST['tan'];
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|
2018-05-26 14:33:15 +02:00
|
|
|
<!doctype html>
|
|
|
|
<html lang="en">
|
2018-05-26 15:59:43 +02:00
|
|
|
<head>
|
2018-05-27 19:31:44 +02:00
|
|
|
<script src="js/entry.js"></script>
|
2018-05-26 15:59:43 +02:00
|
|
|
</head>
|
2018-05-26 14:33:15 +02:00
|
|
|
|
|
|
|
<body>
|
|
|
|
|
2018-05-26 16:55:33 +02:00
|
|
|
<form id="entry-form" action="entry.php" method="post">
|
2018-05-26 15:59:43 +02:00
|
|
|
Vorname:<br>
|
|
|
|
<input type="text" name="vorname"><br>
|
|
|
|
Nachname:<br>
|
|
|
|
<input type="text" name="nachname"><br>
|
|
|
|
E-Mail:<br>
|
|
|
|
<input type="text" name="email"><br>
|
|
|
|
Nachricht:<br>
|
|
|
|
<input type="text" name="eintrag"><br>
|
2018-05-27 19:31:44 +02:00
|
|
|
Tan:<br>
|
|
|
|
<input type="text" name="tan"><br>
|
2018-05-26 15:59:43 +02:00
|
|
|
<input id="absenden" type="submit" value="Abschicken">
|
|
|
|
<button type="reset">Loeschen</button>
|
2018-05-26 14:33:15 +02:00
|
|
|
|
2018-05-26 15:59:43 +02:00
|
|
|
</form>
|
2018-05-26 14:33:15 +02:00
|
|
|
</body>
|
|
|
|
|
|
|
|
</html>
|