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'])){
|
|
|
|
addEntry();
|
|
|
|
consumeTan($_POST['tan']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
$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>
|
|
|
|
<script src="js/newEntry.js"></script>
|
|
|
|
</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>
|
|
|
|
<input type="hidden" name="tan" value="<?php echo $_GET["tan"]?>"><br>
|
|
|
|
<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>
|