Sin descripción

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. require_once 'processes/config.php';
  3. require_once 'processes/dbh.inc.php';
  4. require_once 'processes/checkLogin.php';
  5. if(isset($_POST['id_questionnaire'])) {
  6. $id_questionnaire = mysqli_real_escape_string($connection, trim($_POST['id_questionnaire']));
  7. // Check that questionnaireID is not an empty string
  8. // And that it's registered in the database
  9. if($id_questionnaire === "") {
  10. http_response_code(400);
  11. echo json_encode(array("error" => "Please specify questionnaire ID."));
  12. exit();
  13. } else if(!mysqli_query($connection, "SELECT * FROM questionnair WHERE id = $id_questionnaire;")) {
  14. http_response_code(400);
  15. echo json_encode(array("error" => "Given questionnaire ID ($id_questionnaire) not in database."));
  16. exit();
  17. }
  18. $query = "SELECT * FROM `question` WHERE `id` IN (SELECT `id_question` FROM `questionnair_question` WHERE `id_questionnair`=".$id_questionnaire.");";
  19. $result = mysqli_query($connection, $query);
  20. print '<option disabled selected>Select Question</option>';
  21. while($row = mysqli_fetch_assoc($result)) {
  22. print '<option value="'.$row['id'].'">'.$row['premise'].'</option>';
  23. }
  24. }