corrected tan usage

cant use a tan twice
This commit is contained in:
Marcel Schwarz 2018-05-26 16:55:33 +02:00
parent 57262adcb7
commit 2da917312e
3 changed files with 52 additions and 33 deletions

View File

@ -1,4 +1,53 @@
<?php
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'];
}
?>
<!doctype html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
@ -7,7 +56,7 @@
<body> <body>
<form id="entry-form" action="php/addEntry.php" method="post"> <form id="entry-form" action="entry.php" method="post">
Vorname:<br> Vorname:<br>
<input type="text" name="vorname"><br> <input type="text" name="vorname"><br>
Nachname:<br> Nachname:<br>

View File

@ -1,32 +0,0 @@
<?php
consumeTan($_POST['tan']);
echo "Tan verbraucht " . $_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);
}
$update = $database->query("UPDATE `tans` SET `used`= true WHERE `tan` = '" . $_POST['tan'] . "'");
}
?>

View File

@ -2,6 +2,8 @@
$uniqueID = uniqid(); $uniqueID = uniqid();
$resultStr = "Neuer eintrag über: http://localhost/github/ipr-projekt/entry.php?tan="; $resultStr = "Neuer eintrag über: http://localhost/github/ipr-projekt/entry.php?tan=";
//Final link
//$resultStr = "Neuer eintrag über: http://localhost/friendsbook/entry.php?tan=";
$resultStr = $resultStr . $uniqueID; $resultStr = $resultStr . $uniqueID;
insertTan($uniqueID); insertTan($uniqueID);