title: trying to pull filename from array and INSERT into database
body: <p>i have coded some file upload php code which uploads multiple files, renames them in a loop and submits data on a form.</p>
  
  <p>im now trying to pull the uploaded filenames and INSERT them into database, but at moment struggling to even echo them upon form complete.</p>
  
  <p>can anyone help me get the new filenames and help me with getting the data into my database?</p>
  
  <p>here is some of my code;</p>
  
  <pre><code>&lt;?php
  if(isset($_POST['submit'])){ 
  
  // Variables for date&amp;Time logs
  $dateLog = date("y-m-d"); // DATE OF  ADDITION
  $timeLog = date("H:i:s", time() - 3600);   // TIME OF ADDITION 
  
  // INSERT QUERY
  $sql="INSERT INTO $table1 (firstname, lastname, companyname, phone, email, name, make, serial, catagory, price, location, description, sold, operational, year, clear, rip, version, service, dock, loading, available, extras, dateadded, featured)
  VALUES
  ('$_POST[firstname]',
  '$_POST[lastname]',
  '$_POST[companyname]',
  '$_POST[phone]',
  '$_POST[email]',
  '$_POST[name]',
  '$_POST[make]',
  '$_POST[serial]',
  '$_POST[catagory]',
  '$_POST[price]',
  '$_POST[location]',
  '$_POST[description]',
  'No',
  '$_POST[operational]',
  '$_POST[year]',
  '$_POST[clear]',
  '$_POST[rip]',
  '$_POST[version]',
  '$_POST[service]',
  '$_POST[dock]',
  '$_POST[loading]',
  '$_POST[available]',
  '$_POST[extras]',
  '$dateLog',
  'No')";
  
  
  $query = mysql_query($sql) or die("Cannot query the database.&lt;br&gt;" . mysql_error());
  
  // start of image upload
  $insert_id = mysql_insert_id() or die("Unable to get insert id for image name.&lt;br&gt;" . mysql_error());
  
  extract($_POST);
      $error=array();
      $extension=array("jpeg","jpg","png","gif");
      foreach($_FILES["files"]["tmp_name"] as $key=&gt;$tmp_name)
              {
                  $file_name=$_FILES["files"]["name"][$key];
                  $file_tmp=$_FILES["files"]["tmp_name"][$key];
                  $ext=pathinfo($file_name,PATHINFO_EXTENSION);
                  if(in_array($ext,$extension))
                  {
                      if(!file_exists("../images/listings/".$file_name))
                      {
                          $filename=basename($file_name,$ext);
                          $newFileName=$insert_id."_".mt_rand(1, 99999).".".$ext;
                          move_uploaded_file($file_tmp=$_FILES["files"]["tmp_name"][$key],"../images/listings/".$newFileName);
                      }
                      else
                      {
                          $filename=basename($file_name,$ext);
                          $newFileName=$filename.mt_rand(1, 99999).".".$ext;
                          move_uploaded_file($file_tmp=$_FILES["files"]["tmp_name"][$key],"../images/listings/".$newFileName);
                      }
                  }
                  else
                  {
                      array_push($error,"$file_name, ");
                  }
              }
  // end of image upload
  //echo '&lt;p&gt;This item was added successfully&lt;/p&gt;';
    print_r($newFileName);
  
  }
  ?&gt;
  </code></pre>
  
  <p>and my form items;</p>
  
  <pre><code>1: Upload : &lt;input type="file" name="files[]"/&gt;&lt;br /&gt;
  2: Upload : &lt;input type="file" name="files[]"/&gt;&lt;br /&gt;
  3: Upload : &lt;input type="file" name="files[]"/&gt;&lt;br /&gt;
  4: Upload : &lt;input type="file" name="files[]"/&gt;&lt;br /&gt;
  </code></pre>
  
  <p>Cheers</p>