title: mysql update if exist else insert
body: <p>In my form, I have file type input field that is dynamically generated by add more click button.
  Everything is ok, when I insert the data but i'm facing problem when I update second table which 
  I used for only store file type data.</p>
  
  <p>I have analysed some case:</p>
  
  <pre><code>Case 1: if value exist is equal to new value then update
  Case 2: if value not exist then insert data
  Case 3: if value exist and greater than previous value then update the previous value and insert new data
  case 4: if value exist and less than previous value then update previous and other value will be remain same(no change). 
  </code></pre>
  
  <p>I have tried so far <code>
  $array_filename = trim($array_filename, ","); 
  $filename_array = explode(',', $array_filename); 
  $query = mysql_query("SELECT * FROM</code>tbl_name_2<code>WHERE</code>job_app_id<code>='$editId' "); 
  $res = mysql_fetch_array($query); 
  for($i=0;$i&lt;coun($filename_array);$i++) { 
   $insertQuery = "REPLACE INTO</code>tbl_name_2<code>(</code>id<code>,</code>job_app_id<code>,</code>file_name<code>) VALUES ('$res[$i]','$editId','$filename_array[$i]')"; 
   $isInsert = mysql_query($insertQuery) or die(mysql_error()); 
  }</code></p>
  
  <hr>