Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2011
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unlink function not working

    Hello
    This is my code ,
    i want to delete databse row and image from folder
    it delete only database row,but it not delete image from folder...Why?
    Please Help me

    <?php
    include('config.php');
    $id=$_REQUEST['id'];
    $image=$_REQUEST['image'];
    $target_path='upload/';
    if(isset($_REQUEST['action'])=='delete')
    {
    $query="delete from tbl_user where id='$id'";
    $r1=mysql_query($query) or die(mysql_error());
    unlink($target_path.$image);
    header('Location:welcome.php');

    }

    ?>


    Thank you

  • #2
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    824
    Thanks
    93
    Thanked 18 Times in 18 Posts
    What id suggest trying first is looking at the string its trying to unlink

    PHP Code:
    <?php
    include('config.php');
    $id=$_REQUEST['id'];
    $image=$_REQUEST['image'];
    $target_path='upload/';
    if(isset(
    $_REQUEST['action'])=='delete')
    {
    $query="delete from tbl_user where id='$id'";
    $r1=mysql_query($query) or die(mysql_error());
     echo 
    "".$target_path.$image."";
    }

    ?>
    and checking the path and file are correct.

  • #3
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You can also check the return value from unlink() to see if it's true or false. You should probably comment out your header() call while you're trying to get this working because there may be an error message you're missing due to the immediate redirect.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •