Advertisement
MadeCurler

Delete comment and return to comment

Jan 7th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.38 KB | None | 0 0
  1. /******************comment_photo.php*****************************/
  2.  
  3. <?php include("includes/header.php"); ?>
  4. <?php  if (!$session->is_signed_in()) {redirect("login.php");} ?>
  5. <?php
  6.  
  7. if(empty($_GET['id'])){
  8.         redirect("photos.php");
  9.     }
  10.  
  11.  
  12.     $comments = Comment::find_the_comments($_GET['id']);
  13.    
  14.     $SpecificPhoto=Photo::find_by_id($_GET['id']);    
  15.  
  16.      ?>
  17.  
  18.         <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
  19.            
  20.             <!-- Top Menu Items -->        
  21.             <?php include("includes/top_nav.php");   ?>
  22.             <!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
  23.             <?php include("includes/side_nav.php"); ?>
  24.            
  25.         </nav>
  26.  
  27.         <div id="page-wrapper">
  28.            <div class="container-fluid">
  29.                 <!-- Page Heading -->
  30.                 <div class="row">
  31.                     <div class="col-lg-12">
  32.                         <h1 class="page-header">
  33.                             Comments
  34.                             <!-- <small>Here are your comments</small> -->
  35.                         </h1>
  36.  
  37.                         <a href="add_comment.php" class="btn btn-primary">Add comment</a>
  38.  
  39.         <div class="col-md-12">
  40.             <table class="table table-hover">
  41.                 <thead>
  42.                     <tr>
  43.                         <th>Comment Id</th>
  44.                          <th>Photo</th>
  45.                          <th>Photo Id</th>
  46.                         <th>Author</th>
  47.                         <th>Body</th>
  48.                      
  49.                     </tr>
  50.                 </thead>
  51.  
  52.                 <tbody>
  53.  
  54.                 <?php foreach ($comments as $comment): ?> <!-- $comment is a row in the comments table  -->
  55.                 <tr>
  56.                     <td><?php echo $comment->id; ?></td>
  57. <td><img class="user_small_image " src="<?php echo $SpecificPhoto->picture_path(); ?>"></td>
  58.  
  59.                     <td><?php echo $SpecificPhoto->id; ?>
  60.                     <td><?php echo $comment->author; ?>
  61.                         <div class="action_links">
  62. <a href="delete_comment.php?id=<?php echo $comment->id; ?>&photo=<?php echo $SpecificPhoto->id ?>">Delete</a>
  63.                         </div>
  64.                     </td>
  65.                     <td><?php echo $comment->body; ?></td>
  66.                    
  67.             </tr>
  68.                 <?php endforeach; ?>
  69.  
  70.                 </tbody>
  71.             </table>
  72.  
  73.         </div><!-- end md-12-->
  74.  
  75.                     </div>
  76.                 </div> <!--- row -->
  77.  
  78.             </div> <!-- container fluid-->
  79.            
  80.         </div> <!--end wrapper-->
  81.        
  82.  
  83.   <?php include("includes/footer.php"); ?>
  84.  
  85. /**********************************delete_comment.php******************************/
  86.  
  87. <?php include("includes/init.php"); ?>
  88. <?php  if (!$session->is_signed_in()) {redirect("login.php");} ?>
  89.  
  90. <?php
  91.  
  92. if (empty($_GET["id"])) {
  93.   redirect("comments.php");
  94. }
  95.  
  96.  
  97. // create a new Comment and Photo object and then call the static function find_by_id (which is inherited)
  98. $comment= Comment::find_by_id($_GET["id"]);
  99.  
  100. $photo_redirect = Photo::find_by_id($_GET["photo"]);
  101.  
  102.  
  103. if ($comment) {
  104.     $comment->delete();
  105.     redirect("comment_photo.php?id={$photo_redirect->id}");
  106. } else {
  107.     redirect("comment_photo.php?id={$photo_redirect->id}");
  108. }
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement