Keyword now gets its data from session, made a error pages display

This commit is contained in:
neerholt 2021-03-08 10:29:11 +01:00
parent 5d0e60cd9d
commit 913fdae646
3 changed files with 26 additions and 27 deletions

View File

@ -3,34 +3,36 @@ require "../bootstrap.php";
use Backend\Models\Group; use Backend\Models\Group;
use Backend\Models\KeyWord; use Backend\Models\KeyWord;
session_start();
if (session_status() === PHP_SESSION_ACTIVE) {
if(isset($_POST['submitKeyWord'])){
//Find the group id
$group = Group::find($_SESSION['groupId']);
if(isset($_POST['submitKeyWord'])){ //if statement to find out if the group have use all their keyWords
//Find the group id if(KeyWord::where('group_id', $group->id)->count()<$group->groupAmount){
$group = Group::find($_POST['group_id']);
//if statement to find out if the group have use all their keyWords //Make a new keyword[Only to be used if you need to make a new of something]
if(KeyWord::where('group_id', $group->id)->count()<$group->groupAmount){ $keyword = new KeyWord();
//Make a new keyword[Only to be used if you need to make a new of something] //Take the keyWord the user typed and set it equal to the keyword valuable
$keyword = new KeyWord(); $keyword->keyWord = $_POST['key_word'];
//Take the keyWord the user typed and set it equal to the keyword valuable //Make foreign key from the groups table to the keyWords table
$keyword->keyWord = $_POST['key_word']; $keyword->group()->associate($group);
//Make foreign key from the groups table to the keyWords table //Try to save it
$keyword->group()->associate($group); if(!$keyword->save()){
header("location: ../Frontend/index.php?created=failed");
//Try to save it }else{
if(!$keyword->save()){ header("location: ../Frontend/index.php?created=success");
header("location: ../Frontend/index.php?created=failed"); }
}else{
header("location: ../Frontend/index.php?created=success");
} }
}
//TODO make toast feedback //TODO make toast feedback
}
}else{
header("location: ../Frontend/index.php?login=notLoggein");
} }

View File

@ -1,8 +1,3 @@
<?php
/*
require "../bootstrap.php";
*/
?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
@ -15,7 +10,6 @@ require "../bootstrap.php";
<form action="../Backend/keyWordsRemaining.php" method="POST"> <form action="../Backend/keyWordsRemaining.php" method="POST">
<input type="text" name="key_word" placeholder="key word"> <input type="text" name="key_word" placeholder="key word">
<input type="number" name="group_id" placeholder="group id">
<input type="submit" name="submitKeyWord" value="Submit"> <input type="submit" name="submitKeyWord" value="Submit">
</form> </form>

3
Frontend/index.php Normal file
View File

@ -0,0 +1,3 @@
<?php
print_r($_GET);