I am building a forum with php and MySQL and I want to append current time to each image that users upload for their profile. I used `time()` function on each image file uploaded and it worked for the image file but I have trouble inserting the new filename into the database. I wanted to give each image a unique name to prevent override. 

OK here is what I did: I stored the current time as `$time` and the filename in a variable, `$photo` and I tried to insert that variable’s value using `$photo .= $time` into the database so it has the filename as I did with each uploaded image. However the original filename is inserted into the database in every attempt.
Any workarounds?

```
$image = $_FILES['photo']['name'];
$time = time();
$image .= $time;

```

delete the existing photo

```
delete(image_dir/$row['current_photo.jpg']); 

```

//does not work, but i want something like that

```
if(move_uploaded_file($_FILES['photo']['tmp_name'], 'image_dir/$image') {
   $query = "INSERT INTO profile (user_id, profile_photo) VALUES($id, $image)";
   mysqli_query($dbc, $query);
   if(mysqli_affected_rows($dbc) == 1) { 
       echo "added to the database!"; 
   }else {
      echo "failed to add photo to the database"; 
   }
}else {
   echo "failed to upload photo"; 
} 

```

how can i give the uploaded image unique the name since the original image name gets inserted in the database in every try i make? 

i know the code looks funny :). just want to show the logic.