Please will someone help me with the following code.
The code copies data from one table to another on a button click. When first clicked the script selects and inserts the data ok but I need to check for duplicates and report how many duplicates there are.
I am struugling with identifying the duplicates and reporting back.
<?php
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
//Connect to MySQL using PDO.
$pdo = new PDO("mysql:host=localhost;dbname=tbl_temp_products", "root", "", $options);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//The name of the new table.
$categories = 'categories';
//Import the data from the old table into the new table.
$select = $pdo->prepare('SELECT categories_id, parent_id FROM tbl_temp_categories WHERE categories_id = ?');
$select->execute([$categories]);
if ($select->rowCount() > 0) {
echo 'Duplicates found';
} else {
$pdo->query("INSERT $categories SELECT categories_id, parent_id FROM tbl_temp_categories");
}
}else{
?>
<form method ="post">
<button class="btn btn-primary" type="submit">Update Categories</button>
</form>
<?php } ?>
Thank you for any help you can offer me