title: Unable to submit CSV file to uploader
body: <p>I've made a CSV uploaded where the user must tell the program the exact name of certain columns in the CSV file so it can access and grab data to store in database.  I have some error messages where whenever they don't fill something out that is necessary it will take them back to form to fix what ever mistakes they made.  The issue is it always takes me back and I don't really know why.  </p>
  
  <p>Code for Uploader ---------------------------------------------------------------------</p>
  
  <pre><code>try {  
    # MySQL with PDO_MYSQL  
    $DBH = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);  
    $DBH-&gt;setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
  
  }  
  catch(PDOException $e) { 
      echo "I'm sorry, I'm afraid I can't do that.";  
      file_put_contents('PDOErrors.txt', $e-&gt;getMessage(), FILE_APPEND);   
  }
  
  function returnBack(){
  
      header("Location:csvuploader/csvuploaderform.php?seterror=1");
      exit;
  
  }
  
  if (isset($_POST['submit'])){
  
      /*******************************GET NAME OF COLUMNS IN CSV FILE *********************************************************/
      if (empty($_POST['files'])){
          returnBack();
      }
      if (empty($_POST['firstname'])){
          returnBack();
      }
      if (empty($_POST['lastname'])){
          returnBack();
      }if (empty($_POST['email'])){
          returnBack();
      }
      if (empty($_POST['phone'])){
          returnBack();
      }
      $file = $_FILES['files']['tmp_name'];   
  
      $handle = fopen($file , "r");
  
      $fileop = fgetcsv($handle,1000,",");
  
      $firstname_index = array_search($_POST['firstname'],$fileop);
      if (empty($firstname_index)){
          returnBack();
      }
      $lastname_index = array_search($_POST['lastname'],$fileop);
      if (empty($lastname_index)){
          returnBack();
      }
      $email_index = array_search($_POST['email'],$fileop);
      if (empty($email_index)){
          returnBack();
      }
      $phone_index = array_search($_POST['phone'],$fileop);
      if (empty($phone_index)){
          returnBack();
      }
  
      /***********************ASSIGN COLUMN VALUES TO ACCORDING VARIABLES AND INSERT THEN INTO CSV TABLE IN DB *************************************/
  
  
      while (($fileop = fgetcsv($handle,1000,",")) !== false)
      {
          $firstname = $fileop[$firstname_index];
          $lastname = $fileop[$lastname_index];
          $email = $fileop[$email_index];
          $phone = $fileop[$phone_index];
  
          $insertdata = $DBH-&gt;prepare("INSERT INTO csv (firtname, lastname, email, phone) VALUES ('$firstname','$lastname','$email','$phone')");
          $insertdata-&gt;execute();
      }
      if ($insetdata){
          echo "Successfully Uploaded. Thank you.";   
      }
  }
  </code></pre>
  
  <p>Thank you for your time!</p>
  
  <p>UPDATED ---------------------------</p>
  
  <p>form code</p>
  
  <pre><code>&lt;table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"&gt;
  &lt;tr&gt;
  &lt;form method="post" action="csvuploader.php" enctype="multipart/form-data"&gt;
  &lt;td&gt;
  &lt;table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"&gt;
  &lt;tr&gt;
  &lt;td colspan="3"&gt;&lt;strong&gt;CSV Uploader &lt;/strong&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Enter Name of First Name Column &lt;/td&gt;
  &lt;td&gt;:&lt;/td&gt;
  &lt;td&gt;&lt;input name="fisrtname" type="text" &gt;&lt;?php 
      $setError=$_GET['seterror']; 
      if($setError == 1){
      echo "&lt;span class='errorMsg'&gt;Need Exact Name&lt;/span&gt;";
      }
          ?&gt; &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Enter Name of Last Name Column &lt;/td&gt;
  &lt;td&gt;:&lt;/td&gt;
  &lt;td&gt;&lt;input name="lastname" type="text" &gt;&lt;?php 
      $setError=$_GET['seterror']; 
      if($setError == 1){
      echo "&lt;span class='errorMsg'&gt;Need Exact Name&lt;/span&gt;";
      }
          ?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Enter Name of Email Column &lt;/td&gt;
  &lt;td&gt;:&lt;/td&gt;
  &lt;td&gt;&lt;input name="email" type="text" &gt;&lt;?php 
      $setError=$_GET['seterror']; 
      if($setError == 1){
      echo "&lt;span class='errorMsg'&gt;Need Exact Name&lt;/span&gt;";
      }
          ?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Enter Name of Phone Number Column &lt;/td&gt;
  &lt;td&gt;:&lt;/td&gt;
  &lt;td&gt;&lt;input name="phone" type="text" &gt;&lt;?php 
      $setError=$_GET['seterror']; 
      if($setError == 1){
      echo "&lt;span class='errorMsg'&gt;Need Exact Name&lt;/span&gt;";
      }
          ?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td width="294"&gt;&lt;input type="file" name="files" /&gt;&lt;?php 
      $setError=$_GET['seterror']; 
      if($setError == 1){
      echo "&lt;span class='errorMsg'&gt;Select a File&lt;/span&gt;";
      }
          ?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;br /&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;input type="submit" name="submit" value="Submit" /&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/td&gt;
  &lt;/form&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>