switched tan from unique id to index
This commit is contained in:
parent
09debbdc9d
commit
268a8ea290
@ -13,6 +13,7 @@
|
||||
|
||||
|
||||
<body>
|
||||
<!-- Include the header-->
|
||||
<?php include('segments/_header.html'); ?>
|
||||
|
||||
<div id="content">
|
||||
@ -22,7 +23,7 @@
|
||||
<!-- Zum testen der Daten die ueber die Modals reinkommen -->
|
||||
<!-- <?php include('segments/_indexTestLoginVals.php'); ?> -->
|
||||
|
||||
|
||||
<!-- Include the entryForm-->
|
||||
<?php include('segments/_entryForm.php'); ?>
|
||||
|
||||
<!-- Include the footer-->
|
||||
|
@ -2,7 +2,6 @@ window.addEventListener('load', async () => {
|
||||
console.log("Seite geladen");
|
||||
//getNewUniqueLink();
|
||||
document.getElementById('btnCreateTan').addEventListener('click' , async (event) => getNewUniqueLink());
|
||||
document.getElementById('btnAbsenden').addEventListener('click' , async (event) => createEntry());
|
||||
})
|
||||
|
||||
async function getNewUniqueLink() {
|
||||
@ -17,19 +16,3 @@ async function getNewUniqueLink() {
|
||||
}
|
||||
|
||||
}
|
||||
async function createEntry() {
|
||||
event.preventDefault()
|
||||
console.log("Absenden gedrueckt!!!!");
|
||||
const formData = new formData(document.getElementById('entry-form'));
|
||||
|
||||
try {
|
||||
const response = await fetch('php/login.php', {
|
||||
method: 'post',
|
||||
body: formData
|
||||
});
|
||||
const jsonData = await response.json();
|
||||
|
||||
} catch (e) {
|
||||
console.log("Fehler");
|
||||
}
|
||||
}
|
||||
|
@ -8,22 +8,39 @@
|
||||
|
||||
insertTan($uniqueID);
|
||||
|
||||
$resultStr = getTanID($uniqueID);
|
||||
|
||||
$HTMLJSON = array('html' => $resultStr);
|
||||
echo json_encode($HTMLJSON);
|
||||
|
||||
function insertTan($tan) {
|
||||
require('../dbConnect.php'); //Erstellt variable mit dem namen $database
|
||||
|
||||
$stmt = $database->prepare("INSERT INTO tans (tan, used) VALUES (?, ?)");
|
||||
$stmt = $database->prepare("INSERT INTO tans (tan, userID, used) VALUES (?, ?, ?)");
|
||||
|
||||
$false = false;
|
||||
$stmt->bind_param("si", $tan, $false);
|
||||
$used = false;
|
||||
$userid = 1;
|
||||
$stmt->bind_param("ssi", $tan, $userid, $used);
|
||||
|
||||
try {
|
||||
$stmt->execute();
|
||||
$database->close();
|
||||
} catch (PDOException $e) {
|
||||
$e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
function getTanID($tan){
|
||||
require('../dbConnect.php'); //Erstellt variable mit dem namen $database
|
||||
$abfrage = "SELECT `id` FROM `tans` WHERE `tan` = '" . $tan . "'";
|
||||
|
||||
$ergebnis = mysqli_query($database, $abfrage);
|
||||
|
||||
$row = $ergebnis->fetch_object();
|
||||
$resultStr = $row->id;
|
||||
|
||||
|
||||
return $resultStr;
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
if(isset($_POST['tan'])){
|
||||
if(isset($_POST['tanID'])){
|
||||
//echo "Tan ->" . $_POST['tan'] . "<-";
|
||||
if($_POST['tan'] != ""){
|
||||
if($_POST['tanID'] != ""){
|
||||
addEntry();
|
||||
consumeTan($_POST['tan']);
|
||||
consumeTan($_POST['tanID']);
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,11 +12,11 @@
|
||||
|
||||
}
|
||||
|
||||
function consumeTan($tan) {
|
||||
require('../dbConnect.php'); //Erstellt variable mit dem namen $database
|
||||
function consumeTan($tanID) {
|
||||
require('dbConnect.php'); //Erstellt variable mit dem namen $database
|
||||
|
||||
//Stelle sicher dass die Tan noch verfügbar ist.
|
||||
$abfrage = "SELECT `used`, `tan` FROM `tans` WHERE `tan` = '" . $tan . "'";
|
||||
$abfrage = "SELECT `used`, `tan` FROM `tans` WHERE `id` = '" . $tanID . "'";
|
||||
$ergebnis = mysqli_query($database, $abfrage);
|
||||
|
||||
if($ergebnis->num_rows == 0){
|
||||
@ -26,21 +26,16 @@ function consumeTan($tan) {
|
||||
|
||||
$resultStr = "";
|
||||
|
||||
while ($row = $ergebnis->fetch_assoc()) {
|
||||
$resultStr = $resultStr . $row["used"] . ' ' . $row["tan"] . '<br>';
|
||||
if($row["used"] == 1){
|
||||
$row = $ergebnis->fetch_object();
|
||||
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'] . "'");
|
||||
$update = $database->query("UPDATE `tans` SET `used`= true WHERE `id` = '" . $_POST['tanID'] . "'");
|
||||
|
||||
echo "Tan verbraucht " . $_POST['tan'];
|
||||
echo "Tan verbraucht " . $_POST['tanID'];
|
||||
}
|
||||
|
||||
?>
|
||||
@ -50,7 +45,7 @@ function consumeTan($tan) {
|
||||
<div class="row">
|
||||
|
||||
<div class="col-12">
|
||||
<form id="entry-form" action="" method="post">
|
||||
<form id="entry-form" action="index.php" method="post">
|
||||
<!-- Vorname-->
|
||||
<div class="input-group input-group-sm mb-3">
|
||||
<div class="input-group-prepend">
|
||||
@ -217,14 +212,14 @@ function consumeTan($tan) {
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text" id="inputGroup-sizing-sm">Eintrags-TAN*</span>
|
||||
</div>
|
||||
<input type="text" class="form-control" name="entryTan" aria-label="Small" aria-describedby="inputGroup-sizing-sm">
|
||||
<input type="text" class="form-control" name="tanID" aria-label="Small" aria-describedby="inputGroup-sizing-sm">
|
||||
</div>
|
||||
<!-- Absenden Button-->
|
||||
<div class="modal-footer">
|
||||
<button id="btnAbsenden" type="submit" class="btn btn-primary">Absenden</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</fo+rm>
|
||||
</div>
|
||||
</div>
|
||||
</div> <!-- Ende container entry form -->
|
||||
|
@ -1,5 +1,5 @@
|
||||
CREATE TABLE `kd42696_ipr-projekt`.`entries` (
|
||||
`entryID` INT NOT NULL AUTO_INCREMENT ,
|
||||
`id` INT NOT NULL AUTO_INCREMENT ,
|
||||
`userID` INT NOT NULL ,
|
||||
`tanID` INT NOT NULL ,
|
||||
`vorname` LONGTEXT NOT NULL ,
|
||||
@ -25,7 +25,7 @@ CREATE TABLE `kd42696_ipr-projekt`.`entries` (
|
||||
`story` LONGTEXT NOT NULL ,
|
||||
`absturz` LONGTEXT NOT NULL ,
|
||||
`trinkspiel` LONGTEXT NOT NULL ,
|
||||
PRIMARY KEY (`entryID`),
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE (`userID`),
|
||||
UNIQUE (`tanID`)) ENGINE = InnoDB;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user