# Unlink() probs

**URL:** <https://forum.kirupa.com/t/unlink-probs/193907>\
**Category:** programming\
**Created:** [July 19, 2006, 6:18am UTC](https://forum.kirupa.com/t/unlink-probs/193907 "2006-07-19T06:18:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![james182](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@james182](https://forum.kirupa.com/u/james182)\
**Post date:** [July 19, 2006, 6:18am UTC](https://forum.kirupa.com/t/unlink-probs/193907/1 "2006-07-19T06:18:23Z")

</div>

I’m trying to use the Unlink() statement to delete a image and info from my DB and folder, but it doesn’t delete the right image. It deletes the info correctly just not the image from the folder.

```php

<!-- my link to delete -->
<a href="delete.php?cmd=delete&bId=<?=$bId?>">
<!-- DELETE DATA -->
<?
if($_GET["cmd"]=="delete"){ 
 $bId = $_GET["bId"];
 
 $file = "../images/brochures/$image";
 $fh = fopen($file, 'w') or die("can't open file");
 fclose($fh);
 
 $path = "../images/brochures/";
 $img_file = "$image";
 $file = "$path"."$image";
 if (!unlink($file)){
   echo ("<span class='link'>Error Deleting: $img_file</span><br>");
   }else{
   echo ("<span class='link'>Deleted: $img_file</span><br>");
   }
 
 $sql = "DELETE FROM brochures WHERE bId=$bId";
    $result = mysql_query($sql);
    echo "<br><span class='link'>Information Deleted.</span><br>
   <span class='link'>Go to <a href='admin_home.php' target='_parent'>Admin Home</a></span><br>";
}
?>

```
