No Description

deleteCategory.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. require_once 'config.php';
  3. require_once 'dbh.inc.php';
  4. require_once 'checkLogin.php';
  5. // IF USER ENTERS PAGE AFTER 'Delete Anyway' BUTTON HAS BEEN PRESSED (FROM categories.php), DELETE CATEGORY AND EDIT ASSOCIATED QUESTIONS FROM DATABASE
  6. // ELSE (IF USER ENTERED THIS PAGE WITHOUT SUBMITING A FORM) REDIRECT TO categories.php
  7. if(isset($_POST['deleteCategory'])) {
  8. // NO NEED TO CLEAN ID, SINCE USER NEVER INPUTS ID
  9. $id = $_POST['id'];
  10. // DELETE CATEGORY
  11. $query = "DELETE FROM `category` WHERE `id`='".$id."';";
  12. if(!mysqli_query($connection, $query)) die("Error: ".mysqli_error($connection));
  13. // *EDIT EACH QUESTION SUBCATEGORY THAT CORRESPONDED TO PAST CATEGORY (necesita un while?)
  14. // WARNING: MUST COME BEFORE EDITING QUESTION CATEGORIES
  15. $query = "UPDATE `question` SET `id_subcategory`='-999' WHERE `id_category`='".$id."';";
  16. //if(!mysqli_query($connection, $query)) die("Error: ".mysqli_error($connection));
  17. // *EDIT CORRESPONDING QUESTION'S CATEGORY TO UNKNOWN (necesita un while?)
  18. // WARNING: MUST COME AFTER EDITING QUESTION SUBCATEGORIES
  19. $query = "UPDATE `question` SET `id_category`='-999' WHERE `id_category`='".$id."';";
  20. //if(!mysqli_query($connection, $query)) die("Error: ".mysqli_error($connection));
  21. // *DELETE EACH SUBCATEGORY THAT CORRESPONDED TO PAST CATEGORY (necesita un while?)
  22. $query = "DELETE FROM `subcategory` WHERE `id_categoria`='".$id."';";
  23. //if(!mysqli_query($connection, $query)) die("Error: ".mysqli_error($connection));
  24. }
  25. header('Location: ../categories.php');
  26. exit();