title: SQL Update query when there is an existing date in table by importing .csv files using PHP
body: <p>I have a code that will get to create and insert .csv files to MySQL. Now what I want to get is how to Update my data if there is already an existing date in my table by importing a .csv file.</p>
  
  <p>I tried to do it with a simple Update Query and its working fine... but the tricky part is to get the date from .csv file and compare it to the date that is in MySQL. Can you give me any hints on how to this? </p>
  
  <p>Here's my code:</p>
  
  <pre><code>$file = 'C:\Users\HP\Desktop\csvfiles\ADJTIME.csv';
  $table = 'adjtime';
  
  
      ini_set('auto_detect_line_endings',TRUE);
  $handle = fopen($file,'r');
  // first row, structure
   if ( ($data = fgetcsv($handle) ) === FALSE ) {
  //echo "Cannot read from csv $file";die();
  }
  $fields = array();
  $field_count = 0;
  for($i=0;$i&lt;count($data); $i++) {
  $f = strtolower(trim($data[$i]));
  if ($f) {
  // normalize the field name, strip to 20 chars if too long
  $f = substr(preg_replace ('/[^0-9a-z]/', '_', $f), 0, 100);
  $field_count++;
  
  
   if($f == 'date'){
       $fields[] = '`'.$f.'` DATE()';
  } else {
  $fields[] = '`'.$f.'` VARCHAR(500)';
  
  }
  }
  } 
  
  
  $sqlgetdate = ("SELECT DATE from $table where DATE = '5/3/2017' ");
  
  echo $sqlgetdate;
  $sqlupdate = ("UPDATE $table SET Fieldname = 'John' where DATE = '5/3/2017' ");
  echo $sqlupdate;
  </code></pre>