thanks it was a really silly mistake somehow left out the e of one of the $filenameCode:
$query2 = ("INSERT INTO files (filename,usid,subfolder)VALUES ('$filename', $usid, 0)");
The filename field is given the contents of $filename
If the filename field is blank, then $filename is blank.
Figure out why $filename is blank.
Throw in some
echo $filename ;
to see where you think you have given it a value.