How can a PHP developer prevent duplicate entries of email addresses in a database table using a UNIQUE index?
To prevent duplicate entries of email addresses in a database table using a UNIQUE index, a PHP developer can add a UNIQUE index constraint to the email column in the database table. This will ensure that each email address must be unique, and any attempt to insert a duplicate email address will result in an error.
// Create a UNIQUE index on the email column in the database table
$query = "ALTER TABLE users ADD UNIQUE(email)";
mysqli_query($connection, $query);
// Insert data into the database table
$email = "example@example.com";
$query = "INSERT INTO users (email) VALUES ('$email')";
mysqli_query($connection, $query);