From 913fdae646878c4b8a237e99c4ca49dd7dd27382 Mon Sep 17 00:00:00 2001 From: neerholt Date: Mon, 8 Mar 2021 10:29:11 +0100 Subject: [PATCH] Keyword now gets its data from session, made a error pages display --- Backend/keyWordsRemaining.php | 44 ++++++++++++++++++----------------- Frontend/group.php | 6 ----- Frontend/index.php | 3 +++ 3 files changed, 26 insertions(+), 27 deletions(-) create mode 100644 Frontend/index.php diff --git a/Backend/keyWordsRemaining.php b/Backend/keyWordsRemaining.php index da2ae6a..ffc129a 100644 --- a/Backend/keyWordsRemaining.php +++ b/Backend/keyWordsRemaining.php @@ -3,34 +3,36 @@ require "../bootstrap.php"; use Backend\Models\Group; 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'])){ - //Find the group id - $group = Group::find($_POST['group_id']); + //if statement to find out if the group have use all their keyWords + if(KeyWord::where('group_id', $group->id)->count()<$group->groupAmount){ - //if statement to find out if the group have use all their keyWords - if(KeyWord::where('group_id', $group->id)->count()<$group->groupAmount){ + //Make a new keyword[Only to be used if you need to make a new of something] + $keyword = new KeyWord(); - //Make a new keyword[Only to be used if you need to make a new of something] - $keyword = new KeyWord(); + //Take the keyWord the user typed and set it equal to the keyword valuable + $keyword->keyWord = $_POST['key_word']; - //Take the keyWord the user typed and set it equal to the keyword valuable - $keyword->keyWord = $_POST['key_word']; + //Make foreign key from the groups table to the keyWords table + $keyword->group()->associate($group); - //Make foreign key from the groups table to the keyWords table - $keyword->group()->associate($group); - - //Try to save it - if(!$keyword->save()){ - header("location: ../Frontend/index.php?created=failed"); - }else{ - header("location: ../Frontend/index.php?created=success"); + //Try to save it + if(!$keyword->save()){ + 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"); } - - diff --git a/Frontend/group.php b/Frontend/group.php index 2e19180..dc944c6 100644 --- a/Frontend/group.php +++ b/Frontend/group.php @@ -1,8 +1,3 @@ - @@ -15,7 +10,6 @@ require "../bootstrap.php";
-
diff --git a/Frontend/index.php b/Frontend/index.php new file mode 100644 index 0000000..6443e36 --- /dev/null +++ b/Frontend/index.php @@ -0,0 +1,3 @@ +