خرید بک لینک
Hi I would like to know , how can I check duplicate record, while adding multiple row in Mysql DB in Php?

I'm adding data to my DB from excel sheet using php reader.

Here is my code, what I've tried so far, but its always adding duplicate row without giving any notification/error message.

PHP Code:


$x
=2;
        while(
$x<=$coection->sheets[$sheet]['numRows']) {//04     
        
$bpsuplier = isset($coection->sheets[$sheet]['cells'][$x][1]) ? $coection->sheets[$sheet]['cells'][$x][1] : '';
        
$borp = isset($coection->sheets[$sheet]['cells'][$x][2]) ? $coection->sheets[$sheet]['cells'][$x][2] : '';
        
$bpslno = isset($coection->sheets[$sheet]['cells'][$x][3]) ? $coection->sheets[$sheet]['cells'][$x][3] : '';
        
$bptype = isset($coection->sheets[$sheet]['cells'][$x][4]) ? $coection->sheets[$sheet]['cells'][$x][4] : '';
        
$bprefno = isset($coection->sheets[$sheet]['cells'][$x][5]) ? $coection->sheets[$sheet]['cells'][$x][5] : '';
        
$bpdate = isset($coection->sheets[$sheet]['cells'][$x][6]) ? $coection->sheets[$sheet]['cells'][$x][6] : '';
        
$bpamnt = isset($coection->sheets[$sheet]['cells'][$x][7]) ? $coection->sheets[$sheet]['cells'][$x][7] : '';
        
$bpcurr = isset($coection->sheets[$sheet]['cells'][$x][8])? $coection->sheets[$sheet]['cells'][$x][8] : '';
        
$bpkcgmt = isset($coection->sheets[$sheet]['cells'][$x][9]) ? $coection->sheets[$sheet]['cells'][$x][9] : '';
        
$bpkcgmtfor = isset($coection->sheets[$sheet]['cells'][$x][10]) ? $coection->sheets[$sheet]['cells'][$x][10] : '';
        
$bprmks = isset($coection->sheets[$sheet]['cells'][$x][11]) ? $coection->sheets[$sheet]['cells'][$x][11] : '';

//======================section-001-->check duplicate=====
$resmysqli_query($co,"select * from account where 
factsuply='
$bpsuplier'  and billpay='$borp'     and bpslno='$bpslno'    and bpdtyp='$bptype'    and bprefno='$bprefno' and bpdte='$bpdate'  and ackcgmt='$bpkcgmt'  and bpprog='$bpkcgmtfor'    and acamount='$bpamnt'  and currency='$bpcurr'  and acrmks='$bprmks' ");
 
$total mysqli_num_rows($res);
if(
$total==0)
//======================section-001-->check duplicate=====
  

$insert $co->prepare('
INSERT INTO account (factsuply, billpay, bpslno, bpdtyp, bprefno, bpdte, 
    ackcgmt, bpprog, acamount, currency, acrmks ) 
    VALUES (
    ?, ?, ?, ?,
    ?, ?, ?, ?,
    ?, ?, ?)
   '
);
  
$insert->bind_param(
   
'sssssssssss',
  
$bpsuplier$borp$bpslno$bptype,
  
$bprefno$bpdate$bpamnt$bpcurr,
  
$bpkcgmt$bpkcgmtfor$bprmks );
  
$insert->execute();           
  
$x++;


 
//======================section-001-->message for duplicate entry=====
}
else
 {
   echo 
"This is seems DUPLICATE entry, please go back 
  and do some changes to add new entry."
;
 }
 
//======================section-001-->message for duplicate entry=====

}//04-x2numrows 

برچسب: نویسنده: آیلین رضوانی تاريخ: سه شنبه 5 دی 1396 ساعت: 14:37

صفحه بندی