I suggest that you try and use variable names that are more obviously meaningful. In this case, you are retrieving a filename with a query, and then deleting it. There is a small window of possibility that two users could attempt the same operation on the same file, upon which the second user would not delete anything from the database, from an unlink() is still attempted.
// Retrieve filename of the file we want to delete.
$query = "SELECT fileLocation FROM em WHERE emp = $pr";
$file = mysql_result(mysql_query($query), 0);
// Purge file record from database.
$query = "DELETE FROM em WHERE emp = $pr";
if ($result = mysql_query($query))
{
if (mysql_affected_rows($result) > 0)
{
// Delete file from file system.
echo unlink($file) ? 'File deleted' : 'Error: file not deleted';
}
else
{
// There could have been a race condition, so we assume file is gone.
echo 'File had already been deleted';
}
}
else
{
// Could not execute query.
// Try to handle the error more gracefully, but for now...
die(mysql_error());
}
As for your unlink() problem: you could check the file permissions.