使用图像附件更新数据库记录[关闭]

Hi every one could you please check my code in php. i have problem when i need to update my database record that including with picture, everytime i need to update i need to brow the picture again to update, if not it will overwrite the old picture and blank, So I want it optional for the picture when we update, if we no need update picture i want it still store the old image.

here is my code:

if(isset($_POST["save"])){
$sid = $_POST['sid'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$sex = $_POST['sex'];
$nationality = $_POST['nationality'];
$photo = $_FILES['photo']['tmp_name'];
$dept = $_POST['dept'];
$position = $_POST['position'];
$date = $_POST['date'];
$status = $_POST['status'];
$efile = $_POST['efile'];

if(!isset($photo))
  echo "Please select the photo";
  else
  {
  $photo=addslashes(file_get_contents($_FILES['photo']['tmp_name']));
  $photo_name = addslashes($_FILES['photo']['name']);
  $photo_size = getimagesize($_FILES['photo']['tmp_name']);
  if ($photo_size==FALSE)
  echo "that's not an image.";
 }

 $updateSQL = "UPDATE staff SET sid='$sid', fname='$fname', lname='$lname', sex='$sex', nationality='$nationality', photo='$photo', dept='$dept', position='$position', date='$date', status='$status', efile='$efile' WHERE sid='$_POST[hidden]'";

As far as I understand question,

You want to keep the old image as well as the new images. So why don't you add a unique number as a prefix to your image name. Use function uniqid which generate a unique ID.

Ex :

$file_name = uniqid().$_FILES['photo']['tmp_name'];

Then store $file_name in the database and for the uploaded in the image.

Also keep in mind that your code is vulnerable of SQL injections.