Advertisement
Guest User

delete

a guest
Apr 19th, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. <?php
  2. include_once('../config.php');
  3.  
  4. session_start();
  5.  
  6. if (!isset($_SESSION['loggedIn']))
  7. {
  8. header('Location: login.php');
  9. exit;
  10. }
  11.  
  12. //if there is clicked on the delete button, get id and select al media equal to id
  13. if (isset($_GET['delete']))
  14. {
  15. $delete_id = $_GET['delete'];
  16. $query = "SELECT * FROM media1 WHERE project_project_id = '$delete_id'";
  17.  
  18. //run multiple query
  19. $result = mysqli_query($db, $insertQuery);
  20.  
  21. //check if media exist than delete from folder
  22. while($row = mysqli_fetch_assoc($result))
  23. {
  24. $post_media = $row ['media_image'];
  25. $path = "../img/project_img";
  26.  
  27. if(file_exists($path."/".$post_media))
  28. {
  29. unlink($path."/".$post_media);
  30. }
  31. }
  32.  
  33. //delete all things equal tot id
  34. $emptyQuery = "DELETE project1, media1, tags1 FROM project1
  35. JOIN tags1 ON project_id = tags1.project_project_id
  36. JOIN media1 ON project_id = media1.project_project_id
  37. WHERE project_id = $delete_id";
  38.  
  39. if(mysqli_query($db, $emptyQuery))
  40. {
  41. echo "<script> alert('Je hebt het project succesvol verwijderd')</script>";
  42. echo "<script>window.open('overview_work.php','_self');</script>";
  43. }
  44.  
  45. //close database
  46. mysqli_close($db);
  47. }
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement