title: mysql inserting first field into entire table
body: <p>Okay... I am at a loss here. Turning here for help. </p>
  
  <p>I am trying to insert a csv file full of user information into the database. I am checking to see if the UserID exists first, then if not, using a simple query statement to insert the data for each user.</p>
  
  <p>The problem is, instead of inserting all the user data into one row, it's inserting just the first name into every field in the row.</p>
  
  <p><strong>FirstName</strong>
  *<em>LastName</em>*
  <strong>Address</strong></p>
  
  <p>George George George</p>
  
  <p>I didn't assign an auto-incrementing key, because I already have a USERID I would like to use as a reference. Shouldn't this code be doing what I want?</p>
  
  <pre><code>    $stmt2 = $con-&gt;query("INSERT INTO Persons
                  (First_Name, Middle_Initial, Last_Name, Address, Address2, City, State, Zip_Code,Daytime_Phone,Nighttime_Phone,Customer_ID)
                  VALUES ('$FirstName','$MiddleInitial','$LastName','$Address','$Address2','$City','$State','$Zip','$DayPhone','$NightPhone','$CustomerID')");
  </code></pre>
  
  <p>This is how I am assigning php variables</p>
  
  <pre><code>    if (($handle = fopen("data/" . $File, "r")) !== FALSE) {
  // File is available
  // retrieve one data line at a time
  $row = 1;
  while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
      $num = count($data);
      if ($row == 1) {
          // These are the column names
          $FormattedFields = str_replace(' ', "", $data);
          preg_replace('/[^A-Za-z0-9-]/', '', $FormattedFields);
          foreach ($FormattedFields as $Key =&gt; $UpperField) {
              $LowerField = strtolower($UpperField);
              $NewFields[$Key] = $LowerField;
          }
  
          $FNL = array_search('firstname', $NewFields);
          $LNL = array_search('lastname', $NewFields);
          $MIL = array_search('middleinitial', $NewFields);
          $AL = array_search('middleinitial', $NewFields);
          $A2L = array_search('middleinitial', $NewFields);
          $CL = array_search('middleinitial', $NewFields);
          $SL = array_search('middleinitial', $NewFields);
          $ZL = array_search('middleinitial', $NewFields);
          $DPL = array_search('middleinitial', $NewFields);
          $NPL = array_search('middleinitial', $NewFields);
          $CIDL = array_search('middleinitial', $NewFields);
      } else {
          $FirstName = $data[$FNL];
          $MiddleInitial = $data[$MIL];
          $LastName = $data[$LNL];
          $Address = $data[$AL];
          $Address2 = $data[$A2L];
          $City = $data[$CL];
          $State = $data[$SL];
          $Zip = $data[$ZL];
          $DayPhone = $data[$DPL];
          $NightPhone = $data[$NPL];
          $CustomerID = $data[$CIDL];
  </code></pre>