How can I delete multiple images based on an ID of a record from a table?

55 views Asked by At

I have a system to publish articles with images, but when deleting the article, it deletes only one image and not all the images that were uploaded from that article.

<?php

include('assets/system/core.php');

$id = $_GET['id'];

$consulta = mysqli_query($db, "SELECT * FROM images WHERE id2 = '$id' ");
$registro = mysqli_fetch_assoc($consulta);

$ruta = $registro['file_name'];

unlink("uploads/".$ruta);

$query = mysqli_query($db,"DELETE FROM amenidades WHERE id = '$id'");
$query2 = mysqli_query($db,"DELETE FROM images WHERE id2 = '$id'");
$query3 = mysqli_query($db,"DELETE FROM propiedades WHERE id = '$id'");
$query4 = mysqli_query($db,"DELETE FROM visit_days WHERE id = '$id'");
$query4 = mysqli_query($db,"DELETE FROM comments WHERE prpdad_id = '$id'");
header("LOCATION: ".$web_settings['weblink']."mispropiedades.php");

How could I delete all the images corresponding to a record from my database?

0

There are 0 answers