title: Importing user-uploaded CSV into MySQL
body: <p>I am trying to write a script that will save the contents of a user-uploaded CSV file into a MySQL database. I am not interested in saving the file permanently on the server -- the whole point is to just allow the user to create multiple entries in the MySQL database via a bulk upload. </p>
  
  <p>Here's what I have so far.</p>
  
  <p>HTML upload form</p>
  
  <pre><code>&lt;form enctype="multipart/form-data" action="BulkUploadStudents.php" method="POST"&gt;
  Choose a file to upload: &lt;input name="uploadedfile" type="file" /&gt;&lt;br /&gt;
  &lt;input type="submit" value="Upload File" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>PHP script that saves the contents of a CSV file into a MySQL database</p>
  
  <pre><code>&lt;?php
  
  $username="";
  $password="";
  $database="";
  
  mysql_connect(localhost,$username,$password);
  @mysql_select_db($database) or die( "Unable to select database");
  
  $file_handle = fopen("http://www.example.com/file.csv", "r");
  
  while (!feof($file_handle) ) {
  
  $line_of_text = fgetcsv($file_handle, 1024);
  
  $query = "INSERT INTO students VALUES ('','$line_of_text[0]','$line_of_text[1]','$line_of_text[2]')";
  mysql_query($query);
  
  }
  
  fclose($file_handle);
  
  echo "&lt;p&gt;&lt;b&gt;Records succesfully imported&lt;/b&gt;&lt;/p&gt;";
  
  ?&gt;
  </code></pre>
  
  <p>I basically just need some advice on how to connect the two. I am thinking it would be as easy as naming that PHP script BulkUploadStudents.php, creating a variable for the uploaded file name, and then replacing the "example.com/file.csv" with the variable. Not sure about the specifics, though.</p>
  
  <p>Any help would be greatly appreciated!</p>