booxvid Posted August 8, 2012 Share Posted August 8, 2012 In this program, i would be deleting all images in an album if ever I would choose to delete an album where there's photos in it. <?php require_once("../../includes/initialize.php"); ?> <?php if (!$session->is_logged_in()) { redirect_to("login.php"); } ?> <?php $photo = Photograph::count_all_photosin_album($_GET['album_id']); //$album = Album::find_by_id($_GET['album_id']); if(empty($_GET['album_id'])){ $session->message("No album ID was provided."); redirect_to('list_album.php'); } else{ if($photo>0){ $sql="DELETE FROM album WHERE album_id='".$_GET['album_id']."'"; $result = $database->query($sql); $sql2="DELETE FROM photographs WHERE album_id='".$_GET['album_id']."'"; $result2 = $database->query($sql2); $sql3 = "SELECT * FROM photographs WHERE album_id='".$_GET['album_id']."'"; $result3 = $database->query($sql3); while($row=mysql_fetch_array($result3)){ $photo_id = Photograph::find_by_id($_GET['album_id']); if($photo_id && $photo_id->destroy()){ echo "SUCCESS!"; } } } else{ } } ?> <?php if(isset($database)) { $database->close_connection(); } ?> I already delete the images from my photo table in mysql and also the album record in my album table in mysql but I was unable to delete the images from that album in my directory \: Quote Link to comment https://forums.phpfreaks.com/topic/266830-unable-to-delete-images-from-the-directory/ Share on other sites More sharing options...
requinix Posted August 8, 2012 Share Posted August 8, 2012 ... You're not getting any results from the SELECT because you just deleted them all. Quote Link to comment https://forums.phpfreaks.com/topic/266830-unable-to-delete-images-from-the-directory/#findComment-1367934 Share on other sites More sharing options...
booxvid Posted August 8, 2012 Author Share Posted August 8, 2012 I already transfer the deleting of photos in the database right after deleting the photos in the directory <?php require_once("../../includes/initialize.php"); ?> <?php if (!$session->is_logged_in()) { redirect_to("login.php"); } ?> <?php $photo = Photograph::count_all_photosin_album($_GET['album_id']); if(empty($_GET['album_id'])){ $session->message("No album ID was provided."); redirect_to('list_album.php'); } else{ if($photo>0){ echo "DELETE"; $sql="DELETE FROM album WHERE album_id='".$_GET['album_id']."'"; $result = $database->query($sql); $sql3 = "SELECT * FROM photographs WHERE album_id='".$_GET['album_id']."'"; $result3 = $database->query($sql3); while($row=mysql_fetch_array($result3)){ $target_path =SITE_ROOT.DS."public".DS. "images/".$row['filename']; unlink($target_path); echo "SUCCESS!"; $sql2="DELETE FROM photographs WHERE album_id='".$_GET['album_id']."'"; $result2 = $database->query($sql2); } } else{ } } ?> <?php if(isset($database)) { $database->close_connection(); } ?> but still, the same problem \: Quote Link to comment https://forums.phpfreaks.com/topic/266830-unable-to-delete-images-from-the-directory/#findComment-1367943 Share on other sites More sharing options...
MMDE Posted August 8, 2012 Share Posted August 8, 2012 Try this: $sql3 = "SELECT * FROM photographs WHERE album_id='".$_GET['album_id']."'"; echo $sql3; $result3 = $database->query($sql3) or die(mysql_error()); if(mysql_num_rows($result3)==0){ echo 'no photo found with album_id: '.$_GET['album_id']; } Why is there more than one photo with $_GET['album_id']? Quote Link to comment https://forums.phpfreaks.com/topic/266830-unable-to-delete-images-from-the-directory/#findComment-1367946 Share on other sites More sharing options...
booxvid Posted August 8, 2012 Author Share Posted August 8, 2012 I'm having an album_id property in my photo table which is connected to my album table that has a album_id property as well (: Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/266830-unable-to-delete-images-from-the-directory/#findComment-1367951 Share on other sites More sharing options...
MMDE Posted August 8, 2012 Share Posted August 8, 2012 I'm having an album_id property in my photo table which is connected to my album table that has a album_id property as well (: Thanks for the help! Ah, right, think I confused it with being the photo's ID. Anyways, did you get some useful information when you tried what I posted? I believe it would be interesting for us if you posted the result, at least if you still need any help! Quote Link to comment https://forums.phpfreaks.com/topic/266830-unable-to-delete-images-from-the-directory/#findComment-1367959 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.