updated new entry handling
This commit is contained in:
parent
47934a70be
commit
09debbdc9d
@ -16,16 +16,18 @@
|
||||
<?php include('segments/_header.html'); ?>
|
||||
|
||||
<div id="content">
|
||||
|
||||
<button id="btnCreateTan" type="button" class="btn btn-info">Erstelle Tan</button>
|
||||
</div>
|
||||
|
||||
<!-- Zum testen der Daten die ueber die Modals reinkommen -->
|
||||
<!-- <?php include('segments/_indexTestLoginVals.php'); ?> -->
|
||||
|
||||
|
||||
<?php include('segments/_entryForm.php'); ?>
|
||||
|
||||
<!-- Include the footer-->
|
||||
<?php include('segments/_footer.html'); ?>
|
||||
|
||||
<!-- Optional JavaScript -->
|
||||
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
|
@ -1,7 +1,8 @@
|
||||
window.addEventListener('load', async () => {
|
||||
console.log("Seite geladen");
|
||||
getNewUniqueLink();
|
||||
document.getElementById('btnCreate').addEventListener('click' , async (event) => createEntry());
|
||||
//getNewUniqueLink();
|
||||
document.getElementById('btnCreateTan').addEventListener('click' , async (event) => getNewUniqueLink());
|
||||
document.getElementById('btnAbsenden').addEventListener('click' , async (event) => createEntry());
|
||||
})
|
||||
|
||||
async function getNewUniqueLink() {
|
||||
@ -18,7 +19,8 @@ async function getNewUniqueLink() {
|
||||
}
|
||||
async function createEntry() {
|
||||
event.preventDefault()
|
||||
const formData = new formData(document.getElementById('create-form'));
|
||||
console.log("Absenden gedrueckt!!!!");
|
||||
const formData = new formData(document.getElementById('entry-form'));
|
||||
|
||||
try {
|
||||
const response = await fetch('php/login.php', {
|
||||
|
@ -1,9 +1,56 @@
|
||||
<?php
|
||||
|
||||
if(isset($_POST['tan'])){
|
||||
//echo "Tan ->" . $_POST['tan'] . "<-";
|
||||
if($_POST['tan'] != ""){
|
||||
addEntry();
|
||||
consumeTan($_POST['tan']);
|
||||
}
|
||||
}
|
||||
|
||||
function addEntry() {
|
||||
|
||||
}
|
||||
|
||||
function consumeTan($tan) {
|
||||
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 . "'";
|
||||
$ergebnis = mysqli_query($database, $abfrage);
|
||||
|
||||
if($ergebnis->num_rows == 0){
|
||||
echo "Tan nicht vergeben";
|
||||
return;
|
||||
}
|
||||
|
||||
$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'];
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<!-- Container fuer entry form-->
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
|
||||
<div class="col-12">
|
||||
<form id="entry-form" action="index.php" method="post">
|
||||
<form id="entry-form" action="" method="post">
|
||||
<!-- Vorname-->
|
||||
<div class="input-group input-group-sm mb-3">
|
||||
<div class="input-group-prepend">
|
||||
@ -174,7 +221,7 @@
|
||||
</div>
|
||||
<!-- Absenden Button-->
|
||||
<div class="modal-footer">
|
||||
<button id="entry" type="submit" class="btn btn-primary">Absenden</button>
|
||||
<button id="btnAbsenden" type="submit" class="btn btn-primary">Absenden</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
33
sql/entiresTable.sql
Normal file
33
sql/entiresTable.sql
Normal file
@ -0,0 +1,33 @@
|
||||
CREATE TABLE `kd42696_ipr-projekt`.`entries` (
|
||||
`entryID` INT NOT NULL AUTO_INCREMENT ,
|
||||
`userID` INT NOT NULL ,
|
||||
`tanID` INT NOT NULL ,
|
||||
`vorname` LONGTEXT NOT NULL ,
|
||||
`nachname` LONGTEXT NOT NULL ,
|
||||
`geburtstag` LONGTEXT NOT NULL ,
|
||||
`wohnort` LONGTEXT NOT NULL ,
|
||||
`strasse` LONGTEXT NOT NULL ,
|
||||
`kennenUns` LONGTEXT NOT NULL ,
|
||||
`festnetz` LONGTEXT NOT NULL ,
|
||||
`handynummer` LONGTEXT NOT NULL ,
|
||||
`email` LONGTEXT NOT NULL ,
|
||||
`hobbies` LONGTEXT NOT NULL ,
|
||||
`berufswunsch` LONGTEXT NOT NULL ,
|
||||
`essen` LONGTEXT NOT NULL ,
|
||||
`insel` LONGTEXT NOT NULL ,
|
||||
`film` LONGTEXT NOT NULL ,
|
||||
`sport` LONGTEXT NOT NULL ,
|
||||
`charakter` LONGTEXT NOT NULL ,
|
||||
`tier` LONGTEXT NOT NULL ,
|
||||
`musik` LONGTEXT NOT NULL ,
|
||||
`game` LONGTEXT NOT NULL ,
|
||||
`alk` LONGTEXT NOT NULL ,
|
||||
`story` LONGTEXT NOT NULL ,
|
||||
`absturz` LONGTEXT NOT NULL ,
|
||||
`trinkspiel` LONGTEXT NOT NULL ,
|
||||
PRIMARY KEY (`entryID`),
|
||||
UNIQUE (`userID`),
|
||||
UNIQUE (`tanID`)) ENGINE = InnoDB;
|
||||
|
||||
ALTER TABLE `entries` ADD FOREIGN KEY (`userID`) REFERENCES `user`(`ID`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
ALTER TABLE `entries` ADD FOREIGN KEY (`tanID`) REFERENCES `tans`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
Loading…
Reference in New Issue
Block a user