0 レビュー
0 回答
mysqli-PHPのMysqlDBに複数の行を挿入しているときに、重複レコードをチェックしています
こんにちは。PHPのMysqlDBに複数の行を追加しながら、重複するレコードを確認するにはどうすればよいですか?
phpリーダーを使用してExcelシートからDBにデータを追加しています。
これが私のコードです。これまでに試しましたが、通知やエラーメッセージを表示せずに常に重複する行を追加しています。
$x=2;
while($x<=$connection->sheets[$sheet]['numRows']) {//04
$bpsuplier = isset($connection->sheets[$sheet]['cells'][$x][1]) ? $connection->sheets[$sheet]['cells'][$x][1] : '';
$borp = isset($connection->sheets[$sheet]['cells'][$x][2]) ? $connection->sheets[$sheet]['cells'][$x][2] : '';
$bpslno = isset($connection->sheets[$sheet]['cells'][$x][3]) ? $connection->sheets[$sheet]['cells'][$x][3] : '';
$bptype = isset($connection->sheets[$sheet]['cells'][$x][4]) ? $connection->sheets[$sheet]['cells'][$x][4] : '';
$bprefno = isset($connection->sheets[$sheet]['cells'][$x][5]) ? $connection->sheets[$sheet]['cells'][$x][5] : '';
$bpdate = isset($connection->sheets[$sheet]['cells'][$x][6]) ? $connection->sheets[$sheet]['cells'][$x][6] : '';
$bpamnt = isset($connection->sheets[$sheet]['cells'][$x][7]) ? $connection->sheets[$sheet]['cells'][$x][7] : '';
$bpcurr = isset($connection->sheets[$sheet]['cells'][$x][8])? $connection->sheets[$sheet]['cells'][$x][8] : '';
$bpkcgmt = isset($connection->sheets[$sheet]['cells'][$x][9]) ? $connection->sheets[$sheet]['cells'][$x][9] : '';
$bpkcgmtfor = isset($connection->sheets[$sheet]['cells'][$x][10]) ? $connection->sheets[$sheet]['cells'][$x][10] : '';
$bprmks = isset($connection->sheets[$sheet]['cells'][$x][11]) ? $connection->sheets[$sheet]['cells'][$x][11] : '';
//======================section-001-->check duplicate=====
$res= mysqli_query($conn,"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 = $conn->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
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。