title: Insert the form values from an array into a database
body: <p>I have created a form that allows a user to upload multiple files to a directory. Now I am trying to grab the names of the files from the form input fields and store them into a database.</p>
  
  <p>I am trying to get the array values of the input fields ie; the ['file']['name'] and the ['file']['tmp_name'] and insert them into a database. With the below code I have only managed to get the word "array" to be inserted into the database and not the actual names of the files themselves.</p>
  
  <p>I think I need to loop through the array using a foreach loop but I am uncertain as to how to go about writing it and where to insert it into my code. Below is the code so far:</p>
  
  <pre><code>#connect to the database
      mysql_connect("localhost", "root", "");
      mysql_select_db("masscic");
  
      //Upload Handler to check image types
      function is_image($file) {
  
      $file_types = array('jpeg', 'gif', 'bmp'); //acceptable file types
  
      if ($img = getimagesize($file)){
  
          //echo '&lt;pre&gt;';
          //print_r($_FILES); //will return an array of information for testing
          //print_r($img); //will return an array of information for testing
  
          if(in_array(str_replace('image/', '', $img['mime']), $file_types))
          return $img;
      }
      return false;
  }
      //form submission handling
      if(isset($_POST['submit'])) {
  
      //file variables
  
      $fname = $_FILES['files']['name'];
      $ftype = $_FILES['files']['type'];
      $fsize = $_FILES['files']['size'];
      $tname = $_FILES['files']['tmp_name'];
      $ferror = $_FILES['files']['error'];
      $newDir = '../uploads/'; //relative to where this script file resides
  
      for ($i = count($fname) -1; $i &gt;=0; $i--) {
          if ($ferror[$i] =='UPLOAD ERR OK' || $ferror[$i] ==0) 
  
          {   
  
              if(is_image($tname[$i]))
              {
                  move_uploaded_file($tname[$i], ($newDir.time().$fname[$i])); 
                  echo '&lt;li&gt;&lt;span class="success"&gt;'.$fname[$i].' -- image has been accepted&lt;br&gt;&lt;/span&gt;&lt;/li&gt;';
  
              }else 
                  echo '&lt;li&gt;&lt;span class="error"&gt;'.$fname[$i].' -- is not an accepted file type&lt;br&gt;&lt;/span&gt;&lt;/li&gt;';
          }
      }
  }
              $sqlInsert = mysql_query("INSERT INTO files (file_names) VALUES('$fname')") or die (mysql_error());
  </code></pre>
  
  <p>Thanks for any help.</p>