I have a problem with unlinking photos before deleting the id’s in a prepared statement. The selected ids(of photos) comes through $_POST[‘variable’].
The problem is that it only unlinks ONE photo from the photo folder even if I have selected to delete multiple photos. So it means that the loop is probably not correct.
I wonder if someone can see if there is something wrong with the loop that is supposed to loop through the photo- and thumb paths for the selected photo ids
/* Create the prepared statement */
if ($stmt = $con->prepare("SELECT photo_path, thumb_path FROM photos WHERE photos_id = ?")) {
/* Bind our params */
$stmt->bind_param('i', $photos_id);
/* Execute the prepared Statement - loop through ids*/
foreach ($_POST['variable'] as $photos_id) {
$stmt->execute();
}
/*Get results and loop through seleced photo and thumb paths*/
$stmt->bind_result($photo_path, $thumb_path);
$stmt->store_result();
$numrows = $stmt->num_rows();
if ($numrows){
$I = 0;
while($stmt->fetch()){
unlink("../photos/$photo_path");
unlink("../photos/$thumb_path");
$I++;
}
}
/* Close the statement */
$stmt->close();
} else {
/* Error */
printf("Error: %s\n", $con->error);
}