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