• We just launched and are currently in beta. Join us as we build and grow the community.

PHP Deleting Image In MySQL

lufofola

Intel Collector
L Rep
0
0
0
Rep
0
L Vouches
0
0
0
Vouches
0
Posts
155
Likes
147
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
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
1_80.png

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. $get_id

    =

    $_GET

    [

    'tbl_image_id'

    ]

    ;

  4. // sql to delete a record
  5. $sql

    =

    "Delete from tbl_image where tbl_image_id = '$get_id

    '"

    ;

  6. // use exec() because no results are returned
  7. $conn

    ->

    exec

    (

    $sql

    )

    ;
  8. header

    (

    'location:index.php'

    )

    ;
  9. ?>

Output:

Deleting image.
2_38.png

After deleting the image.
3_6.png


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.


Download
You must upgrade your account or reply in the thread to view hidden text.
 

452,292

323,340

323,349

Top