Browse Source

unique_answer: Check for empty vars before query

When an invalid value is fed to filter_var, the return value will be
nothing. Fix the code to check for empty variables before using them in
queries.
Diego Escalante Urrelo 11 years ago
parent
commit
bed9fc96e3
1 changed files with 4 additions and 0 deletions
  1. 4 0
      main/exercice/unique_answer.class.php

+ 4 - 0
main/exercice/unique_answer.class.php

@@ -468,6 +468,10 @@ class UniqueAnswer extends Question
         $question_id = filter_var($question_id, FILTER_SANITIZE_NUMBER_INT);
         $score       = filter_var($score, FILTER_SANITIZE_NUMBER_FLOAT);
         $correct     = filter_var($correct, FILTER_SANITIZE_NUMBER_INT);
+
+        if (empty($question_id) or empty($score) or empty($correct))
+            return false;
+
         // Get the max position
         $sql      = "SELECT max(position) as max_position FROM $tbl_quiz_answer WHERE question_id = $question_id";
         $rs_max   = Database::query($sql);