title: import and replace multiple columns in database for a particular row using php
body: <p>I have a database table which has 40 columns and a import.php file is there,using which i can upload data from CSV file into the database table. I have made the first column which is named as TND_ID as primary key,which is unique for every row. First i uploaded partial data that is 10 columns data, which has a particular TND_ID. After sometime, i want to upload full data which has 40 columns into the same row in which partial data is present using the import.php. 
  The import.php is:</p>
  
  <pre><code>&lt;?php
  include('db.php');
  include_once "auth.php";
  if(!$link){
      die( "Sorry! There seems to be a problem connecting to our database.");
  }
  
  function get_file_extension($file_name) {
      return end(explode('.',$file_name));
  }
  
  function errors($error){
      if (!empty($error))
      {
              $i = 0;
              while ($i &lt; count($error)){
              $showError.= '&lt;div class="msg-error"&gt;'.$error[$i].'&lt;/div&gt;';
              $i ++;}
              return $showError;
      }// close if empty errors
  } // close function
  
  
  if (isset($_POST['upfile'])){
  // check feilds are not empty
  
  if(get_file_extension($_FILES["uploaded"]["name"])!= 'csv')
  {
  $error[] = 'Only CSV files accepted!';
  }
  
  //if (!$error){
  $tot = 0;
  $handle = fopen($_FILES["uploaded"]["tmp_name"], "r");
  while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) {
      for ($c=0; $c &lt; 1; $c++) {
  
              //only run if the first column if not equal to firstname
              if($data[0] !='firstname'){
                  mysql_query("INSERT INTO new_tnds(`TND_ID`,`Site_name_S1`,`Site_name_S2`,`Call_sign_S1`,`Idea_ID_S1`,`Call_sign_S2`,`Idea_ID_S2`,`Site_to_integrate`,`True_azimuth_S1`,`True_azimuth_S2`,`Path_length_(km)`,`TR_Antenna_diameter_(m)_S1`,`TR_Antenna_diameter_(m)_S2`,`TR_Antenna_height_(m)_S1`,`TR_Antenna_height_(m)_S2`,`#1_Channel_ID_S1`,`#1_Channel_ID_S2`,`#1_Design_frequency_S1`,`#1_Design_frequency_S2`,`Polarization`,`Radio_model_S1`,`Radio_model_S2`,`TX_power_(dBm)_S1`,`TX_power_(dBm)_S2`,`Receive_signal_(dBm)_S1`,`Receive_signal_(dBm)_S2`)VALUES('".mysql_real_escape_string($data[0])."','".mysql_real_escape_string($data[1])."','".mysql_real_escape_string($data[2])."','".mysql_real_escape_string($data[3])."','".mysql_real_escape_string($data[4])."','".mysql_real_escape_string($data[5])."','".mysql_real_escape_string($data[6])."','".mysql_real_escape_string($data[7])."','".mysql_real_escape_string($data[8])."','".mysql_real_escape_string($data[9])."','".mysql_real_escape_string($data[10])."','".mysql_real_escape_string($data[11])."','".mysql_real_escape_string($data[12])."','".mysql_real_escape_string($data[13])."','".mysql_real_escape_string($data[14])."','".mysql_real_escape_string($data[15])."','".mysql_real_escape_string($data[16])."','".mysql_real_escape_string($data[17])."','".mysql_real_escape_string($data[18])."','".mysql_real_escape_string($data[19])."','".mysql_real_escape_string($data[20])."','".mysql_real_escape_string($data[21])."','".mysql_real_escape_string($data[22])."','".mysql_real_escape_string($data[23])."','".mysql_real_escape_string($data[24])."','".mysql_real_escape_string($data[25])."')")or die(mysql_error());
              }
  
      $tot++;}
  }
  fclose($handle);
  $content= "&lt;div class='success' id='message'&gt; CSV File Imported, $tot records added &lt;/div&gt;";
  
  }// end no error
  //}//close if isset upfile
  //$er = errors($error);
  $content = "
  &lt;li align = 'center'&gt;&lt;a href='menu.php'&gt;GO BACK TO MENU&lt;/a&gt;&lt;/li&gt;
  &lt;h3 align = 'center'&gt;Import CSV Data&lt;/h3&gt;
  &lt;form enctype='multipart/form-data' action='' method='post' align = 'center'&gt;
      File:&lt;input name='uploaded' type='file' maxlength='20' /&gt;&lt;input type='submit' name='upfile' value='Upload File'&gt;
  &lt;/form&gt;";
  
  echo $content;
  ?&gt;
  </code></pre>
  
  <p>If i import the data again with the same TND_ID ,it will not take,as that column is a primary key.</p>