PHP Deleting Image In MySQL

Submitted by: 
Language: 
Visitors have accessed this post 1491 times.

PHP Deleting Image In MySQL

In this tutorial, we are going to discuss PHP Deleting Image In MySQL. We're gonna use Delete Statement to delete an image from our database table. This will be easy if you read or follow our previous tutorial in PHP Insert Image In MySQL.

"tbl_image" Example Database Table.

Our Data

Result Data

Deleting Image In MySQL Using PDO

Deleting image in our "tbl_image" table.

Form Field - Modal Form

  1. <!-- Modal -->
  2. <div id="delete<?php echo $id;?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  3. <div class="modal-header">
  4. <h3 id="myModalLabel">Delete</h3>
  5. </div>
  6. <div class="modal-body">
  7. <div class="alert alert-danger">
  8. <?php if($row['image_location'] != ""): ?>
  9. <img src="uploads/<?php echo $row['image_location']; ?>" width="100px" height="100px" style="border:1px solid #333333;">
  10. <?php else: ?>
  11. <img src="images/default.png" width="100px" height="100px" style="border:1px solid #333333; margin-left:15px;">
  12. <?php endif; ?>
  13. <b style="color:blue; margin-left:25px; font-size:30px;"><?php echo $row['first_name']." ".$row['last_name']; ?></b>
  14. <br />
  15. <p style="font-size: larger; text-align: center;">Are you Sure you want to Delete?</p>
  16. </div>
  17. <hr>
  18. <div class="modal-footer">
  19. <button class="btn btn-inverse" data-dismiss="modal" aria-hidden="true">No</button>
  20. <a href="delete.php<?php echo '?tbl_image_id='.$id; ?>" class="btn btn-danger">Yes</a>
  21. </div>
  22. </div>
  23. </div>

DELETE Statement

  1. <?php
  2. require_once('db.php');
  3.  
  4. $get_id=$_GET['tbl_image_id'];
  5.  
  6. // sql to delete a record
  7. $sql = "Delete from tbl_image where tbl_image_id = '$get_id'";
  8.  
  9. // use exec() because no results are returned
  10. $conn->exec($sql);
  11. header('location:index.php');
  12. ?>

Output:

Deleting image.

Result - ModalAfter deleting the image.

Result - Data

Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.


Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.