unlink function not working
<pre><code>&lt;?php

if (isset($_GET['editpic'])) {
    $Id         = $_GET['editpic'];
    //Get Form Data from Data base against the Id
    $Edit_Query = "SELECT product_picture FROM products WHERE id='$Id'";
    $Result     = mysql_query($Edit_Query);
    while ($Row = mysql_fetch_array($Result)) {
        $Old_File_Name = $Row['product_picture'];
    }
}

//To Update Record
if (isset($_POST['update'])) {
    $Id                 = $_POST['id'];
    //To get file
    $Allowed_Extensions = array(
        'jpg',
        'jpeg',
        'png',
        'bmp',
        'gif'
    );
    $Allowed_Size       = 2097152;
    $File_Name          = $_FILES['newfile']['name'];
    $File_Size          = $_FILES['newfile']['size'];
    $File_Tmp           = $_FILES['newfile']['tmp_name'];
    $File_Explode       = (explode('.', $File_Name));
    $File_Extension     = strtolower(end($File_Explode));
    //Form Validation
    $Errormessage       = array();
    if (empty($File_Name)) {
        $Errormessage[] = "Please choose an image for your product";
    }
    if (!in_array($File_Extension, $Allowed_Extensions)) {
        $Errormessage[] = "Please choose only image file";
    }
    if ($File_Size &gt; $Allowed_Size) {
        $Errormessage[] = "Maximum file limit is 2Mb";
    }
    if (empty($Errormessage)) {
        unlink("product_images/" . $Old_File_Name);
        if (move_uploaded_file($File_Tmp, "product_images/" . $File_Name)) {
            //To Rename the uploaded file
            $Random        = rand() * 1200;
            $File_New_Name = $Random . "." . $File_Extension;
            rename("product_images/" . $File_Name, "product_images/" . $File_New_Name);
            $Query  = "UPDATE products SET product_picture='$File_New_Name'    WHERE id='$Id'";
            $Result = mysql_query($Query);
            if ($Result) {
                header("location: manage_inventory.php");
            }

        }


    }

} //End isset update

?&gt;
</code></pre>

<p>Everything is working except the unlink function I can't figure it out what is wrong with my old file variable, it's not deleting the existing file from folder.</p>

<p>Also I need to know why it looses the <code>?edit=$id</code> from url if any validation error occurred in my update.</p>
