diff --git a/index.php b/index.php
index 5e13b41..ea405c7 100644
--- a/index.php
+++ b/index.php
@@ -13,6 +13,7 @@
+
@@ -22,7 +23,7 @@
-
+
diff --git a/js/contentloader.js b/js/contentloader.js
index 25c259d..c541829 100644
--- a/js/contentloader.js
+++ b/js/contentloader.js
@@ -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");
- }
-}
diff --git a/php/generateLink.php b/php/generateLink.php
index 2bfb25d..a3d60a1 100644
--- a/php/generateLink.php
+++ b/php/generateLink.php
@@ -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;
+ }
+
?>
diff --git a/segments/_entryForm.php b/segments/_entryForm.php
index 33436c8..7bd8d50 100644
--- a/segments/_entryForm.php
+++ b/segments/_entryForm.php
@@ -1,10 +1,10 @@
" . $_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"] . '
';
- if($row["used"] == 1){
- echo "Tan schon verbraucht";
- return;
- }
-
+ $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) {
diff --git a/sql/entiresTable.sql b/sql/entiresTable.sql
index aefa654..1069354 100644
--- a/sql/entiresTable.sql
+++ b/sql/entiresTable.sql
@@ -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;