Advertisement
Guest User

index+delete

a guest
May 1st, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. <?php
  2. //include config
  3. require_once('../includes/config.php');
  4.  
  5. //if not logged in redirect to login page
  6. if(!$user->is_logged_in()){ header('Location: login.php'); }
  7.  
  8. //show message from add / edit page
  9. if(isset($_GET['delpost'])){
  10.  
  11. $stmt = $db->prepare('DELETE FROM blog_posts_seo WHERE postID = :postID') ;
  12. $stmt->execute(array(':postID' => $_GET['delpost']));
  13.  
  14. //delete post categories.
  15. $stmt = $db->prepare('DELETE FROM blog_post_cats WHERE postID = :postID');
  16. $stmt->execute(array(':postID' => $_GET['delpost']));
  17.  
  18. header('Location: index.php?action=eliminado');
  19. exit;
  20. }
  21.  
  22. ?>
  23. <head>
  24. <script language="JavaScript" type="text/javascript">
  25. function delpost(id, title)
  26. {
  27. if (confirm("¿Realmente desea eliminar el artículo '" + title + "'?"))
  28. {
  29. window.location.href = 'index.php?delpost=' + id;
  30. }
  31. }
  32. </script>
  33. </head>
  34. <body>
  35.  
  36. <?php include('menu.php');?>
  37.  
  38. <?php
  39. //show message from add / edit page
  40. if(isset($_GET['action'])){
  41. echo '<div class="container"><h3>Articulo '.$_GET['action'].'.</h3></div>';
  42. }
  43. ?>
  44. <div class="container">
  45. <div class="col-md-12 text-right" style="margin: 15px 0 15px 0">
  46. <button class="btn btn-lg btn-primary" ><a href='add-post.php'>Agregar Articulo</a></button>
  47. </div>
  48. <table class="table">
  49. <tr>
  50. <th>Titulo</th>
  51. <th>Fecha</th>
  52. <th>Acción</th>
  53. </tr>
  54. <?php
  55. try {
  56.  
  57. $stmt = $db->query('SELECT postID, postTitle, postDate FROM blog_posts_seo ORDER BY postID DESC');
  58. while($row = $stmt->fetch()){
  59.  
  60. echo '<tr>';
  61. echo '<td>'.$row['postTitle'].'</td>';
  62. echo '<td>'.date('jS M Y', strtotime($row['postDate'])).'</td>';
  63. ?>
  64.  
  65. <td>
  66. <a href="edit-post.php?id=<?php echo $row['postID'];?>">Editar</a> |
  67. <a href="javascript:delpost('<?php echo $row['postID'];?>','<?php echo $row['postTitle'];?>')">Eliminar</a>
  68. </td>
  69.  
  70. <?php
  71. echo '</tr>';
  72.  
  73. }
  74.  
  75. } catch(PDOException $e) {
  76. echo $e->getMessage();
  77. }
  78. ?>
  79. </table>
  80.  
  81. </div>
  82.  
  83. </body>
  84. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement