I have an update.php form which is updating existing data. My problem is when I want to submit and part of my form is dynamic so they can add a new row to mysql while they are updating, so I keep getting duplicate dynamic rows in MySQL which are submitted before.
$i = 0;
while($i<count($fromhours)){
$fromhours[$i]= $fromhours[$i];
$fromminutes[$i]= $fromminutes[$i];
$tohours[$i]= $tohours[$i];
$tominutes[$i]= $tominutes[$i];
$resulthours[$i]= $resulthours[$i];
$resultminutes[$i]= $resultminutes[$i];
$hrscode[$i]= $hrscode[$i];
$gremark[$i]= $gremark[$i];
$query = "INSERT INTO `generalreport` (
`ID`, `date`, `fromhours`, `fromminutes`, `tohours`, `tominutes`, `resulthours`, `resultminutes`, `code`, `remark`
) VALUES (
'".$id."',
'".$date."',
'".$fromhours[$i]."',
'".$fromminutes[$i]."',
'".$tohours[$i]."',
'".$tominutes[$i]."',
'".$resulthours[$i]."',
'".$resultminutes[$i]."',
'".$hrscode[$i]."',
'".$gremark[$i]."'
);";
mysql_query($query);
$i++;
};
How can I use this code for update and just insert new data in MySQL and old data won't be duplicated.