What are the potential pitfalls of allowing duplicate entries in certain columns of a database in PHP?

Allowing duplicate entries in certain columns of a database can lead to data inconsistency and make it difficult to retrieve accurate information. To prevent this issue, you can enforce unique constraints on those columns to ensure that each value is unique.

// Adding a unique constraint to a column in a MySQL table
$sql = "ALTER TABLE table_name ADD CONSTRAINT unique_constraint_name UNIQUE (column_name)";
$result = mysqli_query($conn, $sql);

if ($result) {
    echo "Unique constraint added successfully";
} else {
    echo "Error adding unique constraint: " . mysqli_error($conn);
}