Geen omschrijving

insertQuestion.php 1.1KB

123456789101112131415161718192021222324
  1. <?php
  2. require_once 'config.php';
  3. require_once 'dbh.inc.php';
  4. require_once 'checkLogin.php';
  5. // IF USER ENTERS PAGE AFTER 'Save' BUTTON HAS BEEN PRESSED (FROM bankOfQuestions.php), INSERT QUESTION TO DATABASE
  6. // ELSE (IF USER ENTERED THIS PAGE WITHOUT SUBMITING A FORM) REDIRECT TO bankOfQuestions.php
  7. if(isset($_POST['insertQuestion'])) {
  8. // ONLY HAVE TO CLEAN PREMISE BECAUSE IT'S THE ONLY RAW USER INPUT, THE REST IS VALID DATA ALREADY FROM DATABASE
  9. $premise = mysqli_real_escape_string($_POST['question_premise']);
  10. $id_category = $_POST['question_category'];
  11. $id_subcategory = $_POST['question_subcategory'];
  12. $id_type = $_POST['question_type'];
  13. $id_referencia = $_POST['question_reference'];
  14. $query = "INSERT INTO `question` (`premise`, `id_category`, `id_subcategory`, `id_type`, `id_referencia`) VALUES ('".$premise."', '".$id_category."', '".$id_subcategory."', '".$id_type."', '".$id_referencia."');";
  15. if (!mysqli_query($connection, $query)) die("Error: ".mysqli_error($connection));
  16. }
  17. header('Location: ../bankOfQuestions.php');
  18. exit();