title: PHP File Upload - Ensure both file is uploaded AND database updated
body: <p>What are best practices for uploading files using PHP to ensure that a database is also updated?</p>
  
  <p>Current approach</p>
  
  <p>1)  Form validation confirms all fields are of valid types, lengths and clean of xss attacks.</p>
  
  <p>2)  File uploaded to server with user submitted filename</p>
  
  <p>3)  Database updated with user submitted details including filename</p>
  
  <p>Is that a safe way?  Would it be better to update the database first, then query the database for the filename and then upload the file using the database-retrieved filename?</p>
  
  <p>Not looking for code necessarily but rather the philosophy.  Thanks!</p>