Saturday, April 16, 2016

Uploading Image File With PHP (Delete/Unlink Image File) : Part-07

Database.php
// Delete Data
 public function delete($data){
  $delete_row = $this->link->query($data) 
  or die($this->link->error.__LINE__);
  if ($delete_row) {
   return $delete_row;
  } else {
   return false;
  }
 }
Show Data:
<?php
   $query = "select * from tbl_image";
   $getImage = $db->select($query);
   if ($getImage) {
    $i=0;
    while ($result = $getImage->fetch_assoc()) {
    $i++;
    ?>
   <tr>
    <td><?php echo $i; ?></td>
    <td><img src="<?php echo $result['image']; ?>" height="40px" 
      width="50px"/></td>
    <td><a href="?del=<?php echo $result['id']; ?>">Delete</a></td>
   </tr>
  <?php } } ?>
Delete Data:
<?php
  if (isset($_GET['del'])) {
   $id = $_GET['del'];

   $getquery = "select * from tbl_image where id='$id'";
   $getImg = $db->select($getquery);
   if ($getImg) {
    while ($imgdata = $getImg->fetch_assoc()) {
    $delimg = $imgdata['image'];
    unlink($delimg);
    }
   }
   
   $query = "delete from tbl_image where id='$id'";
   $delImage = $db->delete($query);
   if ($delImage) {
     echo "<span class='success'>Image Deleted Successfully.
     </span>";
    }else {
     echo "<span class='error'>Image Not Deleted !</span>";
    }
   }
  ?>

How to practice tutorials…

  • Make a team with your friends (Member should be 4/5).
  • Start to practice one tutorial series along with them.
  • Don’t try to collect source code. Type the code while watching the tutorial.
  • If you face any problem, post the question in the Forum with the error codes.
  • Share that question Link with your friends or team members to solve quickly.
  • Discuss the problem in the Forum along with others - Video Guidelines.