survey_seahorse

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

delete-survey.php (1154B)


      1 <?php
      2 if (isset($_POST['delete-survey'])) {
      3     include_once 'session.php';
      4     include_once '../config.php';
      5 
      6     $code = mysqli_real_escape_string($connect, $_POST['survey-code']);
      7     if (empty($code)) {
      8         header("Location: ../controlpanel.php?item=empty");
      9         exit();
     10     } else {
     11         echo "Survey ", $code, " deleted ";
     12         echo "<a href = '../controlpanel.php'> Control Panel </a>";
     13         $sql ="SELECT * FROM survey WHERE access_code='$code';";
     14         $result = mysqli_query($connect, $sql);
     15         $row = mysqli_fetch_assoc($result);
     16         $sid = $row['survey_id'];
     17         $deleteAnswers ="DELETE FROM answer_numeric WHERE survey_id=$sid;";
     18         $deleteAnswers ="DELETE FROM answer_bool WHERE survey_id=$sid;";
     19         $deleteQuestions ="DELETE FROM question WHERE survey_id=$sid;";
     20         $deleteSurvey ="DELETE FROM survey WHERE survey_id=$sid;";
     21 
     22         mysqli_query($connect, $deleteAnswers) or die(mysqli_error($connect));
     23         mysqli_query($connect, $deleteQuestions) or die(mysqli_error($connect));
     24         mysqli_query($connect, $deleteSurvey) or die(mysqli_error($connect));
     25         exit();
     26     }
     27 }
     28 ?>
     29