I am relatively new to php and mySQL. I have a database with a user form used to update and create records. I need to allow duplicate key entries to update but I do not want to overwrite existing values in the field. I only want to update the fields that are empty. Here is the code as I have it.
Currently, it does update the field with new information, but it will overwrite existing data with an empty field if it is left empty on update. How can I get it to only update fields that are empty?
Code:
$sql="INSERT INTO Results (a, b, c, d, e, f, g, h, i, j) VALUES ('$_POST[a]','$_POST[b]','$_POST[c]','$_POST[d]','$_POST[e]','$_POST[f]','$_POST[g]','$_POST[h]','$_POST[i]','$_POST[j]') ON DUPLICATE KEY UPDATE f = '$_POST[f]', g = '$_POST[g]', h = '$_POST[h]', i = '$_POST[i]', j = '$_POST[j]'";
Comment