title: Import CSV file into database
body: <p>I'm using following function to import the csv file into db. All is working fine. But I'm also want its also insert <code>$_SESSION['userid']</code> with CSV file. please help me. thanks </p>
  
  <pre><code>    function csv_file_to_mysql_table($source_file, $target_table, $max_line_length=10000) { 
              if (($handle = fopen("$source_file", "r")) !== FALSE) { 
                  $columns = fgetcsv($handle, $max_line_length, ","); 
                  foreach ($columns as &amp;$column) { 
                      $column = str_replace(".","",$column); 
                  } 
                  $insert_query_prefix = "INSERT INTO $target_table (".join(",",$columns).")\nVALUES"; 
                  while (($data = fgetcsv($handle, $max_line_length, ",")) !== FALSE) { 
                      while (count($data)&lt;count($columns)) 
                          array_push($data, NULL); 
                      $query = "$insert_query_prefix (".join(",",quote_all_array($data)).");"; 
                      mysql_query($query); 
                  } 
                  fclose($handle); 
              } 
          } 
  
          function quote_all_array($values) { 
              foreach ($values as $key=&gt;$value) 
                  if (is_array($value)) 
                      $values[$key] = quote_all_array($value); 
                  else 
                      $values[$key] = quote_all($value); 
              return $values; 
          } 
  
          function quote_all($value) { 
              if (is_null($value)) 
                  return "NULL"; 
  
              $value = "'" . mysql_real_escape_string($value) . "'"; 
              return $value; 
          }
          csv_file_to_mysql_table($uploadfile,"import_csv");
          echo "file is imported successfully!";
      }
  </code></pre>