-1

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.

Amir Nikfar
  • 101
  • 1
  • 12
  • might be be similar to this http://stackoverflow.com/questions/5171328/how-to-insert-distinct-records-from-table-a-to-table-b-both-tables-have-same-st – Jigar Jul 05 '15 at 08:56
  • or this http://stackoverflow.com/questions/8756689/avoiding-inserting-duplicate-rows-in-mysql – Jigar Jul 05 '15 at 08:57

2 Answers2

0

i think you have to index your table in mysql such that if any new data enters that have any similar date and entry the mysql will automatically pop out a duplicate entry error

0

Use

INSERT INTO `generalreport` ( 
`ID`, `date`, `fromhours`, `fromminutes`, `tohours`, `tominutes`, `resulthours`, `resultminutes`, `code`, `remark`
) VALUES (...),(...),(...)
M-A-X
  • 325
  • 5
  • 14