survey_seahorse

Software Engineering Project - Fall 2018
Log | Files | Refs | README

commit 9f91b7d63bb0f67d0241e803804ace9b04d8e772
parent e1626698b54e19efb70ab2866307e9453236760d
Author: John Kubach <johnkubach@gmail.com>
Date:   Mon, 17 Dec 2018 22:11:41 -0500

error check for blank questions

questions that are left blank are no longer accepted. any instance of a question that is not filled out will kick a user back to the questions page.

Diffstat:
Mwebsite/res/submit-questions.php | 39++++++++++++++++++++++++---------------
1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/website/res/submit-questions.php b/website/res/submit-questions.php @@ -5,21 +5,30 @@ ini_set('session.cache_limiter','public'); session_cache_limiter(false); session_start(); include_once '../config.php'; - $questions = array(); - - $survey_id = $_SESSION['sid']; - $questions = $_POST['questions']; - - for($counter = 0; $counter < sizeof($questions); $counter++) - { - $q = $questions[$counter]; - echo "Question #".($counter + 1).": ".$questions[$counter]."<br />"; - $sql = "INSERT INTO question (survey_id, question_number, question_content) - VALUES ('$survey_id', $counter + 1, '$q');"; - mysqli_query($connect, $sql) or die(mysqli_error($connect)); +$questions = array(); - } - unset($_SESSION["questions"]); - header("Location: ../success.php"); +$survey_id = $_SESSION['sid']; +$questions = $_POST['questions']; + +for($counter = 0; $counter < sizeof($questions); $counter++) +{ + $q = $questions[$counter]; + + if (empty($q)) { + header("Location: ../questions.php?err=notcomplete"); exit(); + } +} + +for($counter = 0; $counter < sizeof($questions); $counter++){ + echo "Question #".($counter + 1).": ".$questions[$counter]."<br />"; + $sql = "INSERT INTO question (survey_id, question_number, question_content) + VALUES ('$survey_id', $counter + 1, '$q');"; + mysqli_query($connect, $sql) or die(mysqli_error($connect)); +} + + +unset($_SESSION["questions"]); +header("Location: ../success.php"); +exit(); ?>