I think your question is not really reflecting your problem? It seems you actually have problem fetching the image source from the database? Beside the code you provided doesn't help much. maybe post the code that is related to the database activity so we can see what's wrong with updating/fetching the data from the database.
However based on assumptions I will try answer your question.
If no other data is passed along with the request except image update, then the solution should be, move your Database queries into the if block. Meaning.. don't update the database if no image is uploaded.
if (!empty($_FILES['fileToUpload']))
{
$dest = 'images/Uploaded/';
if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $dest.$_FILES['fileToUpload']['name']))
$file = $dest.$_FILES['fileToUpload']['name'];
//database update here
}
because if your database queries happen outside the IF block, the database will get updated anyway, and I assume you pass in the $file variable in the query. and $file in this case will be empty since $file is only defined and given a value in the IF block.
I would love to help you further, but to do so you need to help us with some more information like,
You could share more of your code (you can hide sensitive data)
are there other data sent with the upload that you might need to update the user data in the database but keep the image as is?
If so.. you have 2 options
1) get the current user file before making the update by selecting it from the database, store it in the $file variable before the IF block you stated. If the condition is true, the $file variable will be updated, if not, the $file variable will have the old value you assigned to it which is the current user file.
2) create a dynamic sql query, meaning if a user uploaded a new photo add that to the query, if not don't add it to the query and only update the fields that need to be updated. I'm not familiar with PDO, but the concept is here.