在更新期间将多行插入 MySQL。 [不要插入重复记录]

Insert multiple rows to MySQL during update. [Don't insert duplicate records]

我有一个 update.php 表单正在更新现有数据。我的问题是,当我想提交时,我的部分表单是动态的,因此他们可以在更新时向 mysql 添加新行,所以我不断在 MySQL 中获取重复的动态行,这些行是之前提交的.

$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++;  
};

如何使用此代码进行更新并仅在 MySQL 中插入新数据而不会复制旧数据。

我认为你必须在 mysql 中索引你的 table 这样如果输入任何具有相似日期和条目的新数据 mysql 将自动弹出重复条目错误

使用

INSERT INTO `generalreport` ( 
`ID`, `date`, `fromhours`, `fromminutes`, `tohours`, `tominutes`, `resulthours`, `resultminutes`, `code`, `remark`
) VALUES (...),(...),(...)