In a dashboard i'm looping through all the products from a table. Sometimes there are similair products with the same details. That's why i want to add a duplicate function. So i don't have to retype all the same fields. The basic idea is having a button printed out next to each row which triggers a duplicate function.
while($row = $query->fetch(PDO::FETCH_ASSOC)){
echo "<tr>";
echo "<td>$row['id']</td><td>$row['name']</td><td>$row['brand']</td><td><button>Duplicate</button></td>";
echo "</tr>";
}
I was thinking of connecting a simple insert() function to the button per row.
function insert($value1, $value2, $table){
$stmt->db->prepare("INSERT INTO $table (name, brand) VALUES ($value1, $value2)";
$stmt->execute();
return $stmt;
}
that uses the $row values except for the id because that's auto incremented. I'm not sure if this is the best way to do this.