commit b8616c999bf4d677d70c65fa7b68e3dedd0093b6
parent 795d699a24c34639d5f2c2467f998402de2c695a
Author: John Kubach <johnkubach@gmail.com>
Date: Wed, 19 Dec 2018 18:02:36 -0500
check if user has taken survey
if a user takes a survey that can only be taken once. their results will not be counted on subsequent submissions
Diffstat:
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/website/res/submit-survey.php b/website/res/submit-survey.php
@@ -20,7 +20,7 @@ if (isset($_POST['answers'])) {
for($counter = 0; $counter < sizeof($answers); $counter++) {
$questionNum = $counter+1;
$q = $answers[$counter];
- if ($_SESSION['expired'] != 1) {
+ if ($_SESSION['expired'] != 1 && $_SESSION['taken'] != 1) {
$sql = "INSERT INTO answer_numeric (user_id, survey_id, question_number, answer)
VALUES ('$user', '$survey_id', $counter + 1, $q);";
mysqli_query($connect, $sql) or die(mysqli_error($connect));
@@ -46,7 +46,7 @@ if (isset($_POST['answers'])) {
$type = 49;
$questionNum = $counter+1;
$q = $answers[$counter];
- if ($_SESSION['expired'] != 1) {
+ if ($_SESSION['expired'] != 1 && $_SESSION['taken'] != 1) {
$sql = "INSERT INTO answer_bool (user_id, survey_id, question_number, answer)
VALUES ('$user', '$survey_id', $counter + 1, '$q');";
mysqli_query($connect, $sql) or die(mysqli_error($connect));
@@ -73,7 +73,7 @@ if (isset($_POST['answers'])) {
{
$questionNum = $counter+1;
$q = $answers[$counter];
- if ($_SESSION['expired'] != 1) {
+ if ($_SESSION['expired'] != 1 && $_SESSION['taken'] != 1) {
$sql = "INSERT INTO answer_text (user_id, survey_id, question_number, answer)
VALUES ('$user', '$survey_id', $counter + 1, $q);";
mysqli_query($connect, $sql) or die(mysqli_error($connect));
diff --git a/website/takesurvey.php b/website/takesurvey.php
@@ -66,8 +66,11 @@ if (empty($code)) {
$result = mysqli_query($connect, $sql);
$num_rows = mysqli_num_rows($result);
if ($num_rows > 0) {
- header("Location: res/nope.php");
- exit();
+ $_SESSION['taken'] = 1;
+ echo "<h3> NOTICE: Survey already taken. Your answers will not be counted. </h3>";
+ } else {
+ $_SESSION['taken'] = 0;
+
}
}