title: Updating of photo in upload directory not working
body: <p>I am having a problem in my script to update photo. when i upload a photo to update a particular user, it updates all the user in the mysql table with the photo i uploaded with out renaming it with the <code>staff_id</code>.</p>
  
  <p>According to my script it suppose to rename the photo with the <code>staff_id</code>, updates it to the user and overwrite any photo of that user in upload directory. please what am i doing wrong, my snippet is below:</p>
  
  <pre><code>&lt;?php
  $allowed_filetypes = array('.jpg','.pdf','.xlsx','.xls','.doc','.docx','.ppt','.pptx','.jpeg','.png','.gif','.pdf');
     $max_filesize = 52428800; // max file size = 50MB
     $target = "images/"; 
     $pic=($_FILES['photo']['name']);
   // get form data, making sure it is valid and also sanitize the inputs
  
   $pic = mysql_real_escape_string(htmlspecialchars($_FILES['photo']['name']));
  
    //This gets all the other information from the form
  
  $pic=($_FILES['photo']['name']);
  
      $file = $_FILES['photo']['name']; // Get the name of the file (including file extension).
      $ext = substr($file, strpos($file,'.'), strlen($file)-1);
      if(!in_array($ext,$allowed_filetypes))//check if file type is allowed
          die('The file extension you attempted to upload is not allowed.'); //not allowed
      if(filesize($_FILES['photo']['tmp_name']) &gt; $max_filesize) //check that filesize is less than 50MB
          die ('The file you attempted to upload is too large, compress it below 50MB.');
  
  
     // Connects to your Database
       mysql_connect("localhost", "root", "") or die(mysql_error()) ;
       mysql_select_db("office") or die(mysql_error()) ;
  
  
  $pic=($_FILES['photo']['name']);
  
  
  $uploaddir = 'images/';
  
  $uploadfile = $uploaddir . basename($_FILES['photo']['name']);
  
  echo "&lt;p&gt;";
  if (move_uploaded_file($_FILES['photo']['tmp_name'], $uploadfile)) {
  
  //Writes the information to the database
   mysql_query("UPDATE development SET photo='$pic' ");
   $uploaddir = "images/" .mysql_insert_id() . $ext;  
   $staff_id = mysql_insert_id();
    $new_file_name = mysql_insert_id() . $ext;
  
    //I removed ,photo='$target' to display only id as picture name
    mysql_query("UPDATE development SET photo='$new_file_name' WHERE staff_id=$staff_id");
  
  echo "File is valid, and was successfully uploaded.\n";
  
  } else {
  
     echo "Upload failed";
  
  }
  echo "&lt;/p&gt;";
  
  echo '&lt;pre&gt;';
  
  echo 'Here is some more debugging info:';
  
  print_r($_FILES);
  
  print "&lt;/pre&gt;";
  
  ?&gt; 
  </code></pre>