php - Delete image in database -


I am trying to delete specific images in the database via PHP

I have a page where all the images are displayed in the database and I wanted a button under each of them, so I could have removed them individually through my ID but I Do not know how.

Here is the PHP code to display all the images:

   & Lt ;? Php while ($ row = mysqli_fetch_array ($ result)) {? & Gt; & Lt; H6 & gt; & Lt ;? Php echo $ row ['titleimg']; ? & Gt; & Lt; / h6 & gt; & Lt; P & gt; & Lt ;? Php echo $ line ['events_id']; ? & Gt; & Lt; / P & gt; & Lt; img src = "../../litt/" php echo $ row ["img"] ;? & gt; " Width = "301px" height = "200px" /> & Lt; Form action = "delete_images.php" method = "post" & gt; & Lt; Input type = "submit" name = "delete" value = "delete" /> & Lt; / Form & gt; & Lt ;? Php echo "& lt; br & gt;"; Echo "& lt; br & gt;"; }? & Gt;   

So now, what code should I have in my "delete_images.php" file?

Your form needs an extra piece of information, an identifier to remove the image. Something like this:

  & lt; Form action = "delete_images.php" method = "post" & gt; & Lt; Input type = "hidden" name = "id" value = "& lt ;? php echo $ row ['img_id']? & Gt;" / & Gt; & Lt; Input type = "submit" name = "delete" value = "delete" /> & Lt; / Form & gt;   

Naturally, I'm guessing the name of the column ( img_id ), but any identifier for that specific image will accomplish this trick. With that, your post will be in that value ( $ _ POST ['id'] ) in delete_images.php and it can be used by the database in the DELETE query.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -